combobox默认值的设置问题,求指导决

.Net技术 码拜 9年前 (2016-02-27) 1119次浏览
点击按钮给combobox添加数据,然后查询数据中能否含有def_value2,有的话就把def_value2设置成默认值,但是现在假如第一次添加的数据中存在def_value2,那么默认值就会变成def_value2,然后再次添加,假如没有存在def_value2,默认值还是def_value2,怎么让后续不存在的情况下是combobxox 的默认不显示?(就是那text为空白),本人写的这个判断后就一直是空白了

 //if (this.comboBox2.SelectedIndex > -1)
            //{
            //    comboBox2.Text = "";
            //}
            comboBox2.Items.Add(a_String);
            foreach (var row2 in comboBox2.Items)
            {
                if (Convert.ToString(row2).IndexOf(def_value2) >= 0)
                {
                    int index = this.comboBox2.FindString(Convert.ToString(row2));
                    this.comboBox2.SelectedIndex = index;
                    break;
                }
            }
解决方案

40

if 存在
cmbox.selectedIndex = index
else
cmbox.selectedIndex = -1;

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明combobox默认值的设置问题,求指导决
喜欢 (0)
[1034331897@qq.com]
分享 (0)