how to set default value of combobox in c#
C#
6
Posts
4
Posters
0
Views
1
Watching
-
i fill combobox through datasource but at form load i have to show "None" default value of combobox. how i do it??
-
i fill combobox through datasource but at form load i have to show "None" default value of combobox. how i do it??
Add a "None" item to the collection before you bind it to the control?
modified on Wednesday, April 28, 2010 12:00 PM
-
Add a "None" item to the collection before you bind it to the control?
modified on Wednesday, April 28, 2010 12:00 PM
-
Yes you can:
/// <summary> /// Adds an item to the DataSource of the ComboBox. /// </summary> /// <param name="box">A reference to the combobox.</param> /// <param name="displaymember\_value">The value wich should be displayed.</param> /// <param name="valuemember\_value">The value behind the displayed item.</param> /// <returns>true if succesful otherwise, false.</returns> public bool AddItemToComboDataSource(ref ComboBox box, string displaymember\_value, string valuemember\_value) { bool succes = false; try { DataView view = (DataView)box.DataSource; DataRow row = view.Table.Rows\[0\]; row\[0\] = displaymember\_value; row\[1\] = valuemember\_value; view.Table.Rows.Add(row); box.DataSource = view; succes = true; } //end try catch (Exception ex) { errormsg = ex.Message; } //end catch return succes; } //end method AddItemToComboDataSource
Which is a little cheating, probably, but it works.
V.