How to select item in combobox by key?

Viewed 1263

I fill combobox using the following approach:

 //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"
            });

Then I try to select item in combobox by key:

comboBox1.SelectedItem = data.payment;

Where data.payment is string "2";

How to select item in combobox by key?

2 Answers
Related