点击按钮给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;
cmbox.selectedIndex = index
else
cmbox.selectedIndex = -1;