Link to home
Start Free TrialLog in
Avatar of Richard Comito
Richard ComitoFlag for United States of America

asked on

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

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.
ASKER CERTIFIED SOLUTION
Avatar of ZeonFlash
ZeonFlash

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Richard Comito

ASKER

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
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?
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.