here i have 2 listbox i already have the code for the selected item moving right and moving left but i don't know how to move all of the listbox1 to listbox2 by just click >> or listbox2 to listbox1 <<

Attachments untitled.JPG 9.6 KB

Just use looping.
If you already manage to move single item, then use looping to move all items.

Hi,

Try with this,

Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button.Click
Dim i, j As Integer
i = ListBox1.Items.Count()
For j = 0 To i - 1
ListBox2.Items.Add(ListBox1.Items(j))
Next j
ListBox1.Items.Clear()
End Sub

Actually if you want to transfer ALL items from one listbox to another then you can simple do that like the sample below. No looping needed.

Private Sub MoveToBox2_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
		ListBox2.Items.Clear()
		ListBox2.Items.AddRange(ListBox1.Items)
		ListBox1.Items.Clear()
	End Sub

	Private Sub MoveToBox1_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
		ListBox1.Items.Clear()
		ListBox1.Items.AddRange(ListBox2.Items)
		ListBox2.Items.Clear()
	End Sub

wow thnx geek works like magic

Edited 5 Years Ago by Shodow: n/a

The above sample code is ONLY for the "<<" and ">>" buttons, no selection required. It takes ALL items from listbox1 and moves it to listbox2. But there is a leak...if a user already moved some items from box1 to box2 then those items are lost.
So the question is, do you get the listbox items froma datasource? if so, please tell us from what datasource, so we can adjust the example.

This question has already been answered. Start a new discussion instead.