I have data bind a combo box with a list of values in the database, now, the first record is bein开发者_开发问答g displayed as a default value, i need to change this and set to blank or my custom message, any solution?
You can also set the Text
property of the ComboBox
directly to get a custom message, such as:
comboBox1.SelectedIndex = -1;
comboBox1.Text = "Select an item";
Adding an empty item as the first item to the DataSource before binding is the ugly fix for this issue.
Setting the SelectedIndex as -1 might help.
Below is another option, but you may have to validate when retrieving the selected item.
comboBox.Text = string.Empty;
After binding data to your combobox, insert new item at index 0:
combobox1.Items.Insert(0, "Default Value");
or
combobox1.Items.Insert(0, ""); //Empty
精彩评论