Code:
cmbItemType.DisplayMember = "Text";
cmbItemType.ValueMember = "Value";
var items = new[] {
new { Text = "Text1", Value = "1"},
new { Text = "Text2", Value = "2"}
};
cmbItemType.DataSource = items;
The above code displaying two items, but how to display a blank item in the field. Now at load, it is displaying Text1
without selecting. I want to display a blank item instead of Text1
.
Note: Blank item should not be added to the list, so when selecting the combobox
, I don't want to see a blank item above Text1
display text. Thanks.
The easiest way to clear the second combobox is to just use Reset(). That will clear all the current selections and reset the combobox to its default selection.
You can't "hide" it. You can only remove it. The problem is the source of the data the combo is using. If it's just a list of items you added to the combo, OK, just don't add the item you want to "hide".
To add items to a ComboBox, select the ComboBox control and go to the properties window for the properties of this control. Click the ellipses (...) button next to the Items property.
Or if you want it completely read only you can set Enabled = false , or if you don't like the look of that I sometimes have two controls, one readonly textbox and one combobox and then hide the combo and show the textbox if it should be completely readonly and vice versa. But please note: readonly !=
After you have set items as the DataSource:
cmbItemType.SelectedIndex = -1;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With