I am trying to get the displayed values of all the elements present in comboBox.
The first case : if the comboBox was filled with DataSource:
comboBox.DataSource = myDataSet.Tables[0];
comboBox.DisplayMember = "value";
comboBox.ValueMember = "id";
... I am using this code:
foreach (DataRowView rowView in comboBox.Items) {
String value = rowView.Row.ItemArray[1].ToString();
}
Second case : if the comboBox was filled with comboBox.Items.Add("blah blah"), I use the same code, except that I need to look in the first dimension ItemArray:
foreach (DataRowView rowView in comboBox.Items) {
String value = rowView.Row.ItemArray[0].ToString();
}
Now I would like to get all the values without knowing the schemes used to populate the comboBox. So I do not know if I should use ItemArray[0]or ItemArray[1]. Is it possible? How can i do this?
Otiel source
share