DropDown / Dataset inset blank in top

cc96ai

Member
Joined
Mar 8, 2006
Messages
10
Programming Experience
Beginner
I would like to inset blank or "select" in the top the dropdown,

cbxStoreCategory.DataSource = categoriesBindingSource2;
cbxStoreCategory.DisplayMember = "CategoryCode";

//cbxStoreCategory.Items.Insert(0, "--Select--");

however I cannot do this way, any suggestion ?
 
When a ComboBox is bound to a data source it displays the contents of that data source. If you want to add entries then you have to add them to the data source.

Adding an entry like "--Select--" is pointless because everyone knows that you select an item from a drop-down list in a ComboBox. Do you put "--Enter--" in a TextBox? It is better to leave the ComboBox blank because that makes it more obvious that an entry hasn't been selected, whereas at a glance a ComboBox with "--Select--" in it may appear to already have an entry selected. To clear the selection in a ComboBox you set the SelectedIndex to -1. As you probably realise, when you set the DataSource of a ComboBox the first entry is automatically selected, so you should set the SelectedIndex immediately after if you want a blank entry. You may have to set the SelectedIndex to -1 twice to get it to stick.
 
Back
Top