Multiselection ListBox in VB.Net

VS 2005 / VB.Net / MS Access

I have approximately 60,000 records from table name - DRUGTABLE should be populated to Multiselection ListBox.

Issue is ..

In the Left Handside,I need the Multiselection ListBox
And
In the Right Hand Side, I need a box to load ..
When we select more than one item on left hand side .. each and every new item should go to new box ...

Maximum i should be allowed to select 15 items...

How should i do this ..
chokkaStudentAsked:
Who is Participating?
 
ZhaolaiConnect With a Mentor Commented:
Here it is:

    Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        TextBox1.Text = "You Selected:" & vbNewLine
        For Each item As Object In ListBox1.SelectedItems
            If TextBox1.Lines.Length = 15 Then
                Exit For
            End If
            TextBox1.Text &= item.ToString & vbNewLine
        Next
    End Sub

Open in new window

0
 
John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
What is the box in the right hand...ListBox also?
0
 
chokkaStudentAuthor Commented:
In Right hand side . .. a normal textbox
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
ZhaolaiCommented:
Set your textbox's MultiLine property to True. Then do this:
 

        TextBox1.Text = ""
        For Each item As Object In ListBox1.SelectedItems
            TextBox1.Text &= item.ToString & vbNewLine
        Next

Open in new window

0
 
ZhaolaiCommented:
Oh, you want to limit 15 items in your textbox, do this:

    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
        TextBox1.Text = ""
        For Each item As Object In ListBox1.SelectedItems
            If TextBox1.Lines.Length = 15 Then
                Exit For
            End If
            TextBox1.Text &= item.ToString & vbNewLine
        Next
    End Sub

Open in new window

0
 
chokkaStudentAuthor Commented:
What i am expecting is that

In the below image .. you can see multi list box ...

Here each and every selected item should go to seperate textbox
ListBox.JPG
0
 
John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
why don't you use a second ListBox..Then your Code would like this:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim item As Object
        Me.ListBox2.Items.Clear()
        item = ListBox1.SelectedItem()
        For Each item In Me.ListBox1.SelectedItems
            Me.ListBox2.Items.Add(item)
        Next
    End Sub

Open in new window

0
 
John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
Yeap!!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.