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
168 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
  • 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now