?
Solved

How do I find all that is selected on a ListBox set up for SelectionMode to be MultiSimple.

Posted on 2006-11-29
4
Medium Priority
?
218 Views
Last Modified: 2010-04-28
I have a list box that can have more then one item selected.  But when I do a SelectedValue on the control, all I get is the first value in a string.  This is what I have right now.

    Private Sub btnView_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnView.Click
        Me.txtSubject.Text = Me.lbDBRecipients.SelectedValue.ToString
    End Sub


Thanks.
0
Comment
Question by:Richard Comito
  • 3
4 Comments
 
LVL 17

Accepted Solution

by:
ZeonFlash earned 1500 total points
ID: 18041811
To get a collection of all the selected items, try using the SelectedIndices or SelectedObjects collections.  Here's an example:

Dim selIndices As ListBox.SelectedIndexCollection = lbDBRecipients.SelectedIndices

For i As Integer = 0 To selIndices.Count - 1
    MsgBox("Selected Item #" & i & " = " & lbDBRecipients.Items.Item(selIndices(i)))
Next
0
 

Author Comment

by:Richard Comito
ID: 18041840
ZeonFlash,

thank for your reply.  I copied and pasted what you wrote but cam up with this error:

Operator '&' is not defined for string "Selected Item #0 = " and type 'DataRowView'.

Thanks
0
 

Author Comment

by:Richard Comito
ID: 18041973
This is how I have changed the the code:

    Private Sub btnView_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnView.Click
        Dim selIndices As ListBox.SelectedIndexCollection = lbDBRecipients.SelectedIndices
        Dim strEmailList As String

        strEmailList = ""

        For i As Integer = 0 To selIndices.Count - 1
            strEmailList = strEmailList & lbDBRecipients.Items.Item(selIndices(i)).ToString
        Next

        Me.txtSubject.Text = strEmailList
    End Sub

and this is the result I get:

System.Data.DataRowViewSystem.Data.DataRowViewSystem.Data.DataRowView

Now how do I pull out the value to the selIndices?
0
 

Author Comment

by:Richard Comito
ID: 18042035
ZeonFlash,

This is what I finally came up with:

    Private Sub btnView_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnView.Click
        Dim selIndices As ListBox.SelectedIndexCollection = lbDBRecipients.SelectedIndices
        Dim strEmailList As String

        strEmailList = ""

        For i As Integer = 0 To selIndices.Count - 1
            strEmailList = strEmailList & selIndices(i).ToString & ","
        Next

        Me.txtSubject.Text = strEmailList
    End Sub

Thanks for your help.  However I will have to give this a B because I ended up doing all the trouble shooting myself.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
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…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

850 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