Listbox with datasource, tostring

KingAce

Newcomer
Joined
Jun 26, 2005
Messages
7
I have a listbox with a datasource and a display member, and i have found out that because of the data source, calling
Listbox1.SelectedItem.tostring
will always return
System.Data.DataRowView

So, how can i code this so it returns the test of the selecteditem?
 
Last edited:
I'm sure you looked at the help topic for the members of the DataRowView class, so I'll assume that you just missed the bit that matters. A DataRowView is very similar to a DataRow, and it has an Item property that behaves the same way. You would thus cast the selected item as a DataRowView and then get the field item you want:
Visual Basic:
DirectCast(Me.ListBox1.SelectedItem, DataRowView).Item("test")
or, since Item is the default property, simply
Visual Basic:
DirectCast(Me.ListBox1.SelectedItem, DataRowView)("test")
 
Back
Top