DropDownList SelectedItem returns System.Data.DataRowView???

  • Thread starter Thread starter jim
  • Start date Start date
J

jim

I'm using Oracle with C# for Windows programming... I've bound a
dropdownlist to a dataset (using Oracle Data Adapter, Oracle
Connection).

Whenever I attempt to retrieve the SelectedItem of the DropDownList in
a SelectedIndexChange event... I am returned "System.Data.DataRowView"
instead of the SelectedItem's text.

I can retrieve the selected value using SelectedValue but NOT the
"text."

What am I doing wrong?

Is this a bug with C#, Oracle, and Windows forms programming?

I'm using a DropDownList not the default dropdown.

Thanks in advance... please help!!!
 
In .net, a list control (listbox or combo box) can hold any object, not just
text. When you retrieve the SelectedItem as you discovered you are getting a
view of the record in the bound table that was selected. You will need to
use the properties of the DataRowView (check it out in help) to get the
text. You're not doing anything wrong, that's how it works.

Matt
 
Not sure if there is an easier way but you should be able extact the column you want as follows

((DataRowView)listControlName.SelectedItem)["TheColumnNameYouWant"].ToString()
 
Back
Top