我使用以下方法填充组合框:
//Setup data binding
this.comboBox1.DataSource = dataSource;
this.comboBox1.DisplayMember = "Name";
this.comboBox1.ValueMember = "Value";
var dataSource2 = new List<Status>();
dataSource2.Add(new Status()
{
Name = "Первый раз",
Value = "1"
});
dataSource2.Add(new Status()
{
Name = "Повторно",
Value = "2"
});
然后我尝试按键选择组合框中的项目:
comboBox1.SelectedItem = data.payment;
data.payment
是字符串&#34; 2&#34 ;;
如何按键选择组合框中的项目?
答案 0 :(得分:3)
comboBox.SelectIndex = comboBox.FindStringExact("Повторно")
或
comboBox.SelectedValue = "2"
答案 1 :(得分:1)
您可以使用 SelectedValue
,
comboBox.SelectedValue = "2"
或使用 Linq
this.comboBox1.SelectedItem = dataSource2.SingleOrDefault(t=>t.Value == "2");