ComboBox刷新问题


ComboBox数据绑定刷新问题

问题描述:

//第一次给comboBox.DataSource赋值  显示 的是正确 List<string> instrumentList = new List<string>() { "111111", "22222222", "333333" }; comboBox1.DataSource=instrumentList;   //第二次再给comboBox.DataSource赋值 List<string> newList = new List<string>() { "444", "555", "666" }; comboBox1.DataSource=newList;   //   结果还是上次的内容:"111111""22222222""333333"   解决办法,当comboBox.DataSource需要重新赋值时,先将comboBox.DataSource赋值为null,再进行赋值,如下所示: List<string> newList = new List<string>() { "444", "555", "666" }; comboBox1.DataSource=null; comboBox1.DataSource=newList;