[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
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
?
215 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
[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 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

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

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 …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

650 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