VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Move listbox items

by Blues Scatman (1 Submission)
Category: Coding Standards
Compatability: VB Script
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (2 Votes)

I was asked how to move items in a listbox up and down, to place then in any order of my choice.
Here's one way of doing it. You need two buttons, I named them 'buttonUp' and 'buttonDown', and ofcourse a listbox named 'List1'. Then all you have to do is select the item you wish to move, and press the up or down button. Great for playlists.
Scatman

Rate Move listbox items


Private Sub buttonDown_Click()
 Dim nItem As Integer
 With list1
 If .ListIndex < 0 Then Exit Sub
 nItem = .ListIndex
 If nItem = .ListCount - 1 Then Exit Sub
 .AddItem .Text, nItem + 2
 .RemoveItem nItem
 .Selected(nItem + 1) = True
 End With
End Sub
'----------------------------------------
Private Sub ButtonUp_Click()
 Dim nItem As Integer
 With list1
 If .ListIndex < 0 Then Exit Sub
 nItem = .ListIndex
 If nItem = 0 Then Exit Sub
 .AddItem .Text, nItem - 1
 .RemoveItem nItem + 1
 .Selected(nItem - 1) = True
 End With
End Sub

Download this snippet    Add to My Saved Code

Move listbox items Comments

No comments have been posted about Move listbox items. Why not be the first to post a comment about Move listbox items.

Post your comment

Subject:
Message:
0/1000 characters