Click here to Skip to main content
15,880,543 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

How to move up and move down multiple listbox items within the listbox.

Thanks and Regards,
GSS
Posted

1 solution

try this
VB
Private Sub UpClick()
	' only if the first item isn't the current one
	If listBox1.ListIndex > 0 Then
		' add a duplicate item up in the listbox
		listBox1.AddItem(listBox1.Text, listBox1.ListIndex - 1)
		' make it the current item
		listBox1.ListIndex = (listBox1.ListIndex - 2)
		' delete the old occurrence of this item
		listBox1.RemoveItem(listBox1.ListIndex + 2)
	End If
End Sub

Private Sub DownClick()
	' only if the last item isn't the current one
	If (listBox1.ListIndex <> -1) AndAlso (listBox1.ListIndex < listBox1.ListCount - 1) Then
		' add a duplicate item down in the listbox
		listBox1.AddItem(listBox1.Text, listBox1.ListIndex + 2)
		' make it the current item
		listBox1.ListIndex = listBox1.ListIndex + 2
		' delete the old occurrence of this item
		listBox1.RemoveItem(listBox1.ListIndex - 2)
	End If
End Sub
 
Share this answer
 
v3
Comments
Gssankar 7-Feb-14 6:18am    
Thanks for your response Basmeh, Your code is in Classic vb.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900