[英]C# - Change index of ComboBox item?
I have a combobox that I want to be able to add items to the beginning of. 我有一个组合框,希望将其添加到开头。 For example, when you click it, you get 1,2,3 , but I want to be able to add an option, 0, so that when you click it you get 0,1,2,3.
例如,当您单击它时,您会得到1,2,3,但是我希望能够添加一个选项0,因此,当您单击它时,您将得到0,1,2,3。
Is this possible without rebuilding the combobox? 是否可以在不重建组合框的情况下实现?
只需使用组合框的Items属性的Insert方法:
myComboBox.Items.Insert(0, "New item at top");
Yes, you can use the Insert()
method on the Items
property of your ComboBox
object. 是的,您可以在
ComboBox
对象的Items
属性上使用Insert()
方法。
var comboBox = new ComboBox();
comboBox.Items.Add("1");
comboBox.Items.Add("2");
comboBox.Items.Add("3");
comboBox.Items.Insert(0, "0");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.