To move list-box item up and down . Try below code
To move Up
Private Sub CMD_UP_Click()
If Me.lst_selectedfields.ListCount = 0 Then Exit Sub
If Me.lst_selectedfields.ListIndex = 0 Then Exit Sub
Dim i As Long, j As Long, valtoadd As String, bl As Boolean
bl = False
For i = 0 To Me.lst_selectedfields.ListCount - 1
If Me.lst_selectedfields.Selected(i) = True Then
valtoadd = Me.lst_selectedfields.Column(0, i)
Me.lst_selectedfields.RemoveItem (i)
bl = True
j = i - 1
End If
Next
If bl = False Then Exit Sub
Me.lst_selectedfields.AddItem valtoadd, j
Me.lst_selectedfields.ListIndex = j
End Sub
To move Down
Private Sub CMD_DOWN_Click()
If Me.lst_selectedfields.ListCount = 0 Then Exit Sub
If Me.lst_selectedfields.ListIndex = Me.lst_selectedfields.ListCount - 1 Then Exit Sub
Dim i As Long, j As Long, valtoadd As String, bl As Boolean
bl = False
For i = 0 To Me.lst_selectedfields.ListCount - 1
If Me.lst_selectedfields.Selected(i) = True Then
valtoadd = Me.lst_selectedfields.Column(0, i)
Me.lst_selectedfields.RemoveItem (i)
bl = True
j = i + 1
End If
Next
If bl = False Then Exit Sub
Me.lst_selectedfields.AddItem valtoadd, j
Me.lst_selectedfields.ListIndex = j
End Sub
We keep moving forward, opening new doors, and doing new things, because we're curious and curiosity keeps leading us down new paths. See the link below for more info.
ReplyDelete#moving
www.inspgift.com