DropDownList SelectedItem returns System.Data.DataRowView???

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!!!
 
M

md

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
 
G

Guest

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()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top