Moving Items in a Multicolumn List Box

  • Thread starter paul.m.henderson
  • Start date
P

paul.m.henderson

Hi,

I have an unbound listbox, which has a dynamically created value list
as its row source (note: the values are created dynamically, but the
number of columns is constant). I'd like a way to move its items up or
down. I found the following code, which works well for a single column
list box, but I can't figure out how to alter it for multicolumns. Any
ideas? Thanks!

public sub cmdDown_Click()

'moves the selected item in the list down

Dim lst As ListBox
Dim lngLoop As Long
Dim strTemp As String

'lstTest is name of list box.
Set lst = Me!lstTest
If Not IsNull(lst) Then
With lst
Select Case .ListIndex
Case .ListCount - 1
'Last item. Make last item first.
strTemp = .ItemData(.ListIndex) & ";"
For lngLoop = 0 To .ListCount - 2
strTemp = strTemp & .ItemData(lngLoop) & ";"
Next lngLoop
.RowSource = strTemp
Case Else
For lngLoop = 0 To .ListIndex - 1
strTemp = strTemp & .ItemData(lngLoop) & ";"
Next lngLoop
strTemp = strTemp & .ItemData(.ListIndex + 1) & ";" &
..ItemData(.ListIndex) & ";"
For lngLoop = .ListIndex + 2 To .ListCount - 1
strTemp = strTemp & .ItemData(lngLoop) & ";"
Next lngLoop
.RowSource = strTemp
End Select
End With
End If
Set lst = Nothing

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top