Jsn*_*dnl 0 c# synchronization combobox list winforms
有什么方法可以将 myList<string>与 a同步ComboBox?
我想要的是我的 ComboBox,它根据列表的变化自动更新它的内容。
我已经尝试使用该ComboBox.DataSource属性,但这不会更新 ComboBox,它只会填充一次,仅此而已,所以......
使用BindingSource对象。
List<string> list = new List<string>();
BindingSource bsource=new BindingSource();
//Set list dataSource
bsource.DataSource = list;
comboBox1.DataSource = bsource;
//Now add an element via Binding object
bsource.Add("One");
bsource.Add("Two");
Run Code Online (Sandbox Code Playgroud)
或者您可以尝试创建 IList Adapter 包装器的ArrayList.Adapter方法。
ArrayList 项;
items=ArrayList.Adapter(comboBox1.Items);
items.Add("one");
Run Code Online (Sandbox Code Playgroud)