Eu preenho combobox usando a seguinte abordagem:
//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"
});
Então eu tento selecionar o item na caixa de combinação pela chave:
comboBox1.SelectedItem = data.payment;
Onde data.payment
é string "2";
Como selecionar item na caixa de combinação por tecla?
Respostas:
3 para resposta № 1comboBox.SelectIndex = comboBox.FindStringExact("Повторно")
ou
comboBox.SelectedValue = "2"
1 para resposta № 2
Você pode usar SelectedValue
,
comboBox.SelectedValue = "2"
ou usando Linq
this.comboBox1.SelectedItem = dataSource2.SingleOrDefault(t=>t.Value == "2");