Is it possible to run through every item in a combobox using a foreach
loop? How would I do it?
The thing is I have a System.Data.DataRowView
there because the combobox is attached to a DataTable
. How do I convert from that to string
?
Generally, it looks like this:
foreach(object item in myComboBox.Items)
{
DataRowView row = item as DataRowView;
if(row != null)
{
string displayValue = row["myColumnName"].ToString();
// do something
}
else
// error: item was not of type DataRowView
}
also see http://msdn.microsoft.com/en-us/library/system.windows.forms.combobox.items.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With