swapping items in a list

  • Thread starter Thread starter GJP
  • Start date Start date
G

GJP

Hello.

Im trying to swap items in a list box

For example. you select a item(s) in list box A, click a button and it will
move it to list box B.

I can get it to move to a text box, but not to a list.

Sorry if very simple question, im new to VB...
 
* "GJP said:
Im trying to swap items in a list box

For example. you select a item(s) in list box A, click a button and it will
move it to list box B.

I can get it to move to a text box, but not to a list.

\\\
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

' Add the item to the 2nd listbox.
Me.ListBox2.Items.Add(Me.ListBox1.SelectedItem)

' Remove it from the 1st listbox.
Me.ListBox1.Items.Remove(Me.ListBox1.SelectedItem)
End Sub
///
 
\\\
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
' Add the item to the 2nd listbox.
Me.ListBox2.Items.Add(Me.ListBox1.SelectedItem)

' Remove it from the 1st listbox.
Me.ListBox1.Items.Remove(Me.ListBox1.SelectedItem)
End Sub
///

Thank you!

That allows me to move one iten, now if i want to select serveral will i
need to build in a loop?

Atleast my main headache has now been solved, thanks again.
 
* "GJP said:
That allows me to move one iten, now if i want to select serveral will i
need to build in a loop?

That will be the easiest solution. Notice that you can add multiple
items when using the 'Items.AddRange' method.
 
Back
Top