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
205 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:GabicusC
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 17

Accepted Solution

by:
ZeonFlash earned 500 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:GabicusC
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:GabicusC
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:GabicusC
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

728 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