Getting ComboBox selected value from System.Windows.Forms
combo.ValueMember = "variate_id";
combo.DisplayMember = "variate_name";
combo.DataSource = dataset.Tables;
What happened here is when I bind the DefaultView of the table to the ComboBox object, I get a DataRowView as SelectedValue/SelectedIndex, which is not what I wanted to.
What work for me is to get the DataRowView and get the SelectedValue in ItemArray
DataRowView row = (DataRowView)combo.SelectedItem;
int x = (int)row.Row.ItemArray; //this will return the selected variate_id
I wonder why SelectedValue is not working, the way it works on the web counterpart.
Getting ComboBox selected value from System.Windows.Forms Reviewed by czetsuya on Monday, September 28, 2009 Rating: