Akash Thakare
Akash Thakare

Reputation: 22972

DropDownList Showing First Item Empty

enter image description here

Every time this Dropdown is showing first Item Blank

 ComboBox cb;
 List<string> namesCollection=new List<string>();
 namesCollection.Add("---- Select ----");
 namesCollection.Add("ABC1");
 namesCollection.Add("ABC2");
 namesCollection.Add("ABC3");
 namesCollection.Add("ABC4");
 foreach(string pname in namesCollection)
 cb.Items.Add(pname);

Does anyone have solution for this ?

Upvotes: 0

Views: 2167

Answers (2)

TaW
TaW

Reputation: 54433

You probably have a line feed in your items collection. Hard to see. Adding a cb.Items.Clear() before populating is probably a good idea anyway and will get rid of the problem, if you can't locate it.

Upvotes: 1

Grant Winney
Grant Winney

Reputation: 66439

You appear to be defining the ComboBox right there in your code, so I'll assume it's actually displayed somewhere in your form / window.

It's normal for the ComboBox to display a blank line initially.

Specify the item you want to display, immediately after populating the ComboBox with data:

cb.SelectedIndex = 0;

Upvotes: 1

Related Questions