Tech
Forums
Jobs
Books
Events
Live
Interviews
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
2
Reply
Comboboxcolumn in gridview 'almost' working... 'default' value doesn't display when initializing
Dick
Jan 17 2011 2:10 PM
13.5k
Reply
Using:
--Visual Studio 2010
--Winform app
--.net 4.0
I've got a Forms application that is using a comboboxcolumn in a gridview. The data is sourced from an XML file but I need to add a column to the Gridview which is a 'drop-down' list from which the user can make various choices.
Everything seems to work (drop-down list created, user can select item from list, I can read selected item, etc; almost perfect).
The only thing that doesn't work is that upon initialization, I can't seem to display the default value. I can set the default value, and I know it is set because I can retrieve the data which verifies indeed that the default has been set correctly.
But all I see in the gridview is a blank column when I start; if I select an item from the drop-down list, the selected item is displayed.
Basic code snippets here:
// Read XML data
AlarmTypes.dsAlarms.ReadXml(
fsReadXml);
// Bind data to gridview
AlarmsGridView.DataSource = AlarmTypes.dsAlarms;
//Create new comboboxcolumn control
DataGridViewComboBoxColumn comboboxColumn = new DataGridViewComboBoxColumn();
// initialize combobox list
foreach (string s1 in ObservationNames)
comboboxColumn.Items.AddRange(
s1);
// add control to gridview
AlarmsGridView.Columns.Insert(
0, comboboxColumn);
// some stuff I've tried (among dozens of other things; following code sets default but it is still
// not displayed upon initialization
DataGridViewComboBoxCell cell = (DataGridViewComboBoxCell) AlarmsGridView.Rows[0].Cells[
0];
cell.Value = "berry"; // this is 3rd item in list (and yes, 'berry' is spelled correctly in list)
cell.Selected = true;
Any ideas?
Thanks.
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
2
)
Next Recommended Forum
Treeview
form with backgroundimage and transparency problem when i show or hide a label.