KingAce Posted June 30, 2005 Posted June 30, 2005 (edited) 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? Edited June 30, 2005 by KingAce Quote
jmcilhinney Posted July 1, 2005 Posted July 1, 2005 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:DirectCast(Me.ListBox1.SelectedItem, DataRowView).Item("test")or, since Item is the default property, simplyDirectCast(Me.ListBox1.SelectedItem, DataRowView)("test") Quote
jmcilhinney Posted July 3, 2005 Posted July 3, 2005 So' date=' how can i code this so it returns the [b']test[/b] of the selecteditem?You put the name of the field in that position. You said "test" so I said "test". Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.