Listboxes

D

Dag

Hello there! I have a problem here. For many of you it
would not be a problem at all, but I am new in
programming...so here is the question:

I have a form with two listboxes in it....Listbox1 and
Listbox2. Listbox1 contains some names and listbox2
contains nothing. if I doubleclick Listbox1 all names in
that listbox will be transferred to listbox2 (Listbox1
will now be empty and Listbox2 filled)...the next thing
is...Solution 1: if I doubleclick listbox2 all the names
will be deleted...or solution 2: all the names will be
transferred back again....

Thanx in advance
DG, Norway
 
C

Colin McGuire

Hi Dag, this might be what you are after or point you in the right
direction. Just paste it into your application with the two listboxes
(ListBox1 and ListBox2) on the form.
Happy to help
Colin


Private Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles ListBox1.DoubleClick
ListBox2.Items.AddRange(ListBox1.Items())
ListBox1.Items.Clear()
End Sub


Private Sub ListBox2_DoubleClick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles ListBox2.DoubleClick
Dim answer As MsgBoxResult = MsgBox("Answer 'Yes' to clear listbox 2
or 'No' to transfer content from listbox 2 to listbox 1",
MsgBoxStyle.YesNoCancel, "Transfer or Clear")
If answer = MsgBoxResult.Yes Then
ListBox2.Items.Clear()
Else
ListBox1.Items.AddRange(ListBox2.Items())
ListBox2.Items.Clear()
End If
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
ListBox2.Items.Clear()
ListBox1.Items.Clear()
ListBox1.Items.Add("John")
ListBox1.Items.Add("Ringo")
ListBox1.Items.Add("Paul")
ListBox1.Items.Add("George")
End Sub
 
J

Jan Nielsen

Hi DG

Private Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles ListBox1.DoubleClick
Dim a As Object
For Each a In ListBox1.Items
ListBox2.Items.Add(a)
Next
ListBox1.Items.Clear()
End Sub

Private Sub ListBox2_DoubleClick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles ListBox2.DoubleClick
' Solution 1
ListBox2.Items.Clear()
'Solution2
Dim a As Object
For Each a In ListBox2.Items
ListBox1.Items.Add(a)
Next
ListBox2.Items.Clear()
End Sub


Best regards

Jan
 
H

Herfried K. Wagner [MVP]

* "Dag said:
I have a form with two listboxes in it....Listbox1 and
Listbox2. Listbox1 contains some names and listbox2
contains nothing. if I doubleclick Listbox1 all names in
that listbox will be transferred to listbox2 (Listbox1
will now be empty and Listbox2 filled)...the next thing
is...Solution 1: if I doubleclick listbox2 all the names
will be deleted...or solution 2: all the names will be
transferred back again....

\\\
Private Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
Me.ListBox2.Items.AddRange(Me.ListBox1.Items)
Me.ListBox1.Items.Clear()
End Sub

Private Sub ListBox2_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox2.DoubleClick
Me.ListBox1.Items.AddRange(Me.ListBox2.Items)
Me.ListBox2.Items.Clear()
End Sub
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top