I have a ComboBox which is populated on form load. I get the data from the database in the form of a dataset and use the following to populate the combobox.
checkBox4_combo.DataSource = ds.Tables[0].DefaultView.ToTable(true,"Work_Location");
checkBox4_combo.DisplayMember = "Work_Location";
checkBox4_combo.BindingContext = this.BindingContext;
But, when I try accessing the items of this combobox, it returns an undesirable output.
I have tried the following:
Method 1:
object ob = checkBox4_combo.Items[0];
MessageBox.Show(ob.ToString());
//Returns "System.Data.DataRowView"
Method 2:
checkBox4_combo.SelectedIndex = 1;
object ob = checkBox4_combo.SelectedItem;
//OR
object ob = checkBox4_combo.SelectedValue;
MessageBox.Show(ob.ToString());
//Returns "System.Data.DataRowView"
Method 3:
checkBox4_combo.SelectedIndex = 1;
object ob = checkBox4_combo.SelectedText;
MessageBox.Show(ob.ToString());
//Returns <blank>
But, if I use:
checkBox4_combo.SelectedIndex = 1;
object ob = checkBox4_combo.Text;
MessageBox.Show(ob.ToString());
I will get the desired output but that means that the selected text gets changed. So essentially, I would not want to use this, and methods 2 & 3.
Now, besides asking for a solution, I want to understand why the output is either null or "System.Data.DataRowView". Is there something in the way that I am binding the data to the combobox which is a problem? Or is this how it works and I should stick to my last solution?