private void Form3_Load(object sender, EventArgs e)
{
List<object> list = new List<object>();
list.Add(new { Text = "1", Value = "1000" });
list.Add(new { Text = "2", Value = "2000" });
list.Add(new { Text = "3", Value = "3000" });
comboBox1.DataSource = list;
comboBox1.DisplayMember = "Text";
comboBox1.ValueMember = "Value";
SetComboBoxSelected(this.comboBox1, "2000");
}
public void SetComboBoxSelected(ComboBox comboBox,string key)
{
for (int i = 0; i < comboBox.Items.Count; i++)
{
dynamic obj = comboBox.Items[i];
if (obj.Value.ToString() == key)
{
string text = obj.Text.ToString();
comboBox.SelectedIndex = comboBox.FindString(text);
}
}
}