Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conversion from type 'DataRowView' to type 'String' Error

Status
Not open for further replies.

ProjectExplorer

Programmer
Mar 22, 2002
95
GB
I have Combobox which is filled via a dataset and datatable as follows.

'Get table from the dataset
DT = DS.Tables(0)

'Fill the ComboBox
With cboMediaCode
.DataSource = DT
.ValueMember = "MID"
.DisplayMember = "MediaCode"
End With

How do I retrieve the ValueMember ("MID") value?

I am using cboMediaCode.SelectedItem but am getting this error: "Conversion from type 'DataRowView' to type 'String' is not valid."

It was all going so well!! Please help.
 
Did you try:

cboMediaCode.SelectedValue

or if you need it as a string:

cboMediaCode.SelectedValue.ToString



=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
VB.NET Programmer
 
Many thanks for your response.

After a little trial and error I managed to come up with a solution.

Because I am loading the ComboBox from a Dataset, the Combox contains a collection of data row (objects) not just simple numbers.

To get to the Value Member and Display Member I created a instance of a DataRowView object, set it the Combobox.SelectedItem and used the DataRowView.Item to get to the values. Not too painful.

E.G.

Dim DRV as DataRowView = cboMediaCode.SelectedItem
strMediaCode = DRV.Item("MID").ToString

....unless of course someone knows a better way !!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top