Solved

Multiselection ListBox in VB.Net

Posted on 2010-09-15
8
379 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
  • 3
  • 3
  • 2
8 Comments
 
LVL 18

Expert Comment

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

Author Comment

by:chokka
Comment Utility
In Right hand side . .. a normal textbox
0
 
LVL 17

Expert Comment

by:Zhaolai
Comment Utility
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
 
LVL 17

Expert Comment

by:Zhaolai
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:chokka
Comment Utility
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
Comment Utility
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 500 total points
Comment Utility
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
Comment Utility
Yeap!!!
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now