C# ComboBox遍历和List<string> 数据绑定

学习记录

List<string> cmb = new List<string>(); //集合

ComboBox遍历(一)

for (int i = 0; i < comboBox2.Items.Count; i++)
{
    cmb.Add(comboBox2.GetItemText(comboBox2.Items[i]));
}

数据绑定

//cmb.AddRange(new string[]{"中国","朝鲜","朝鲜","日本","法国","美国"}); //为集合赋值
comboBox1.DataSource = cmb; //控件绑定集合

ComboBox遍历(二)  (没有测试)

foreach (System.Data.DataRowView dr in comboBox1.Items)
{
    string id = dr["student_id"].ToString();
    string nane = dr["student_name"].ToString();
}

猜你喜欢

转载自www.cnblogs.com/susiesnai-sun/p/12366957.html
今日推荐