开发者

adding extra items on top of ComboBox DataSource

I need to add an item in the top of co开发者_运维技巧mbobox datasource. Is it possible? If so, you can I do that?


When the datasource of your combobox derives from IList, you will be able to use the Insert method, which provides you with a way to add an item at a place that you desire (whereas the Add method adds the item on the bottom of you list). If you place your item at position 0 (zero) then the item will appear on top of the list, like this:

IList comboboxDataSource = new List<string>();
comboboxDataSource.Add("one");
comboboxDataSource.Add("two");
comboboxDataSource.Add("three");

comboboxDataSource.Insert(0, "Please choose an item");
comboBox1.DataSource = comboboxDataSource;

For more information: http://msdn.microsoft.com/en-us/library/system.collections.ilist.insert.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜