Microsoft Office Tutorials and References
In Depth Information
ListBox Techniques
The event-handler procedures for the two CommandButtons follow:
Private Sub MoveUpButton_Click()
Dim NumItems As Integer, i As Integer, ItemNum As Integer
Dim TempItem As String, TempList()
If ListBox1.ListIndex <= 0 Then Exit Sub
NumItems = ListBox1.ListCount
Dim TempList()
ReDim TempList(0 To NumItems - 1)
‘ Fill array with list box items
For i = 0 To NumItems - 1
TempList(i) = ListBox1.List(i)
Next i
‘ Selected item
ItemNum = ListBox1.ListIndex
‘ Exchange items
TempItem = TempList(ItemNum)
TempList(ItemNum) = TempList(ItemNum - 1)
TempList(ItemNum - 1) = TempItem
ListBox1.List = TempList
‘ Change the list index
ListBox1.ListIndex = ItemNum - 1
End Sub
Private Sub MoveDownButton_Click()
Dim NumItems As Integer, i As Integer, ItemNum As Integer
Dim TempItem As String, TempList()
If ListBox1.ListIndex = ListBox1.ListCount - 1 Then Exit Sub
NumItems = ListBox1.ListCount
Dim TempList()
ReDim TempList(0 To NumItems - 1)
‘ Fill array with list box items
For i = 0 To NumItems - 1
TempList(i) = ListBox1.List(i)
Next i
‘ Selected item
ItemNum = ListBox1.ListIndex
‘ Exchange items
TempItem = TempList(ItemNum)
TempList(ItemNum) = TempList(ItemNum + 1)
TempList(ItemNum + 1) = TempItem
ListBox1.List = TempList
‘ Change the list index
ListBox1.ListIndex = ItemNum + 1
End Sub
 
Search JabSto ::




Custom Search