?
Solved

MultiExtended ListBox SelectedValue

Posted on 2005-05-16
6
Medium Priority
?
3,626 Views
Last Modified: 2011-10-03
What is the proper way to extract the SelectedValue property from a data bound ListBox that has multiple selections?
0
Comment
Question by:Erick37
  • 3
  • 3
6 Comments
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 14015927
Hi Erick;

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
0
 
LVL 32

Author Comment

by:Erick37
ID: 14017449
Hi Fernando,  

I get the following error using your suggestion:

An unhandled exception of type 'System.InvalidCastException' occurred in microsoft.visualbasic.dll
Additional information: Cast from type 'DataRowView' to type 'String' is not valid.
0
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 14018174
Hi Erick;

What is stored in the Listbox and how was it declared?

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 32

Author Comment

by:Erick37
ID: 14018427
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.
0
 
LVL 64

Accepted Solution

by:
Fernando Soto earned 1000 total points
ID: 14018799
Hi Erick;

Try this out

Dim SelectItems As DataRowView

For Each SelectItems In ListBox1.SelectedItems
    Console.WriteLine("Display Member = {0}", SelectItems.Row.ItemArray(0))
    Console.WriteLine("Value Member = {0}", SelectItems.Row.ItemArray(1))
Next
0
 
LVL 32

Author Comment

by:Erick37
ID: 14019236
That is exactly what I was looking for, thanks!

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Screencast - Getting to Know the Pipeline
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question