C # ComboBox traversal and List <string> Data Binding

Learning Record

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

 

ComboBox traverse (a)

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

Data Binding

// cmb .AddRange (new new String [] { "China", "Korea", "Korea", "Japan", "French", "US"}); // set of assignments for the
comboBox1.DataSource = cmb ; // control is bound collection

 

ComboBox traversal (b) (not tested)

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

Guess you like

Origin www.cnblogs.com/susiesnai-sun/p/12366957.html