?
Solved

Multiselection ListBox in VB.Net

Posted on 2010-09-15
8
Medium Priority
?
392 Views
Last Modified: 2012-05-10
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 ..
0
Comment
Question by:chokka
[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
  • 3
  • 2
8 Comments
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33684578
What is the box in the right hand...ListBox also?
0
 

Author Comment

by:chokka
ID: 33684680
In Right hand side . .. a normal textbox
0
 
LVL 17

Expert Comment

by:Zhaolai
ID: 33684918
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 17

Expert Comment

by:Zhaolai
ID: 33685141
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
 

Author Comment

by:chokka
ID: 33686256
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
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33686690
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
 
LVL 17

Accepted Solution

by:
Zhaolai earned 2000 total points
ID: 33686726
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
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33686746
Yeap!!!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses

801 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