遍历ComboBox的内容

// 一:
for (int i = 0; i < comboBox1.Items.Count; i++)
{
    MessageBox.Show(comboBox1.GetItemText(comboBox1.Items[i]));
}

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

//for (int i = 0; i < comboBox1.Items.Count; i++)
//{
//    DataRowView dr = (DataRowView)comboBox1.Items[i];
//    string id = dr["student_id"].ToString();
//    string nane = dr["student_name"].ToString();
//}

//三:

for (int i = 0; i < comboBox1.Items.Count; i++)
{
    comboBox1.SelectedIndex = i;
    string value = comboBox1.SelectedValue.ToString();
}

 

posted @ 2015-09-10 13:22  网络飞侠  阅读(1233)  评论(0编辑  收藏  举报