winform combox中,sql语句获取value值与combox的value匹配后,显示对应的text值
在winform 的combox中已经添加了value和text
combo = new ComboBoxItem();
combo.Text = "a";
combo.Value = 12;
cmb.Items.Add(combo);
combo = new ComboBoxItem();
combo.Text = "b";
combo.Value = 16;
cmb.Items.Add(combo);
在页面中,我需要在代码中选中值,显示text,比如,我现在想要显示“a”,但是现在数据库,我根据关键字,只能获得value,这时,我需要根据数据库的value来跟页面的value进行匹配,匹配后显示对应的text。
[最优解释]
/// <summary>
/// ComboBox类控件,文本和值
/// </summary>
public class ComboBoxHelp
{
public string Text { set; get; }
public string Value { set; get; }
public ComboBoxHelp(string txt, string val)
{
this.Text = txt;
this.Value = val;
}
public ComboBoxHelp()
{
}
public override string ToString()
{
return Text;
}
}
// 绑定
for (int i = 0; i < 10; i++)
{
string Text = i;
string Value = i;
ddlBQQK.Properties.Items.Add(new ComboBoxHelp(Text, Value));
}