Erick37
asked on
MultiExtended ListBox SelectedValue
What is the proper way to extract the SelectedValue property from a data bound ListBox that has multiple selections?
ASKER
Hi Fernando,
I get the following error using your suggestion:
An unhandled exception of type 'System.InvalidCastExcepti on' occurred in microsoft.visualbasic.dll
Additional information: Cast from type 'DataRowView' to type 'String' is not valid.
I get the following error using your suggestion:
An unhandled exception of type 'System.InvalidCastExcepti
Additional information: Cast from type 'DataRowView' to type 'String' is not valid.
Hi Erick;
What is stored in the Listbox and how was it declared?
What is stored in the Listbox and how was it declared?
ASKER
It is a bound listbox using the NorthWind database for testing. Settings are as follows:
DataSource: DataSet11.Sales_by_Year
DisplayMember: OrderID
ValueMember: ShippedDate
Using ListBox2.SelectedValue will return the correct value for the ValueMember for only the currently selected item. I need to retrieve the value for all selections because the ListBox is set as MultiExtended, so multiple items can be selected.
Thanks.
DataSource: DataSet11.Sales_by_Year
DisplayMember: OrderID
ValueMember: ShippedDate
Using ListBox2.SelectedValue will return the correct value for the ValueMember for only the currently selected item. I need to retrieve the value for all selections because the ListBox is set as MultiExtended, so multiple items can be selected.
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That is exactly what I was looking for, thanks!
This can be accomplished by doing the following.
For Each selected As String In ListBox1.SelectedItems
' Each time through the loop
' will give the next selected item
' from the list box
Console.WriteLine(selected
Next
I hope this was of some help
-Fernando