chokka
asked on
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 ..
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 ..
What is the box in the right hand...ListBox also?
ASKER
In Right hand side . .. a normal textbox
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
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
ASKER
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
In the below image .. you can see multi list box ...
Here each and every selected item should go to seperate textbox
ListBox.JPG
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Yeap!!!