comboBox value

  • Thread starter Thread starter juli jul
  • Start date Start date
J

juli jul

Hello ,I am trying to get the comboBox value but when I am writing:
MessageBox.Show(this.comboBoxdb.SelectedValue.ToString());
I get the following result:
System.Data.DataRowView
instead of the selected value . Why?
 
You'll get that "value" being returned because you're data binding to the
ComboBox. Cast the SelectedValue to a DataRowView and then you can get the
appropriate value from the Row property and desired column.
 
Thanks but I the casting fails - how can I do it (I tried to create new
DataRowView and than asign the SelectedValue to it but it didn't work)
How to do it?
Thank you!
 
Try something like this.

((DataRowView)this.comboBoxdb.SelectedValue).Row[this.comboBoxdb.ValueMember
].ToString()
 
How do you bind the data to the comboBox?
Try to use 2 property during binding will help you DisplayMember &
ValueMember.
 
That's the way I am binding the data to combobox:
this.comboBoxdb.DataSource =
ds_db.Tables[0]; this.comboBoxdb.DisplayMember = "name";
but I can't get the selected value,how can I get it?
Thanks!
 
hi,

When you set the valueMember property make sure it is case sensitive.

HTH

Regards,

das
 
Back
Top