110,561
社区成员
发帖
与我相关
我的任务
分享
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.Items.Add("a");
comboBox1.Items.Add("b");
comboBox1.Items.Add("c");
comboBox1.Items.Add("d");
int index = -1;
for (int i = 0; i < comboBox1.Items.Count; i++)
{
if ("c" == comboBox1.Items[i].ToString())
{
index = i;
break;
}
}
comboBox1.SelectedIndex = index;
}
comboBox1.DataSource = dt;
comboBox1.DisplayMember = "cty_name";
comboBox1.ValueMember = "cty_id";
comboBox1.SelectedValue = "2"; //假设B对应的cty_id是2