当前位置: 代码迷 >> C# >> C# winForm combobox动态加载数据后不能设置选中项解决方法
  详细解决方案

C# winForm combobox动态加载数据后不能设置选中项解决方法

热度:67   发布时间:2016-05-05 03:27:50.0
C# winForm combobox动态加载数据后不能设置选中项
如题:
combobox1.selectedItem = 值,不好使
combobox1.selectedItem的值为null是怎么回事

应该怎么写能设置选中项
------解决思路----------------------
肯定是可以的,你检查一下你是如何动态添加的。

 private void button1_Click(object sender, EventArgs e)
        {
            this.comboBox1.Items.Add("Text1");
            this.comboBox1.Items.Add("Text2");
            this.comboBox1.Items.Add("Text3");
            this.comboBox1.Items.Add("Text4");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.comboBox1.SelectedText = "Text4";
        }
  相关解决方案