I have a listbox where selected items that include 3 fields (
ClassRank, ClassNumber, ClassDescription) are added in order for me to re-order them:
I have being able to get code working to move items up and down within the listbox.
However, when the item is moved only the first of the 3 fields are visible. How do I get all three fields to be displayed in the new position?
ClassRank, ClassNumber, ClassDescription) are added in order for me to re-order them:
Code:
Dim varItem As Variant
Dim strAdd As String
Dim columnCount As Integer
Dim i As Integer
columnCount = List12.columnCount
For Each varItem In List12.ItemsSelected
For i = 0 To columnCount - 1
If strAdd = "" Then
strAdd = List12.Column(i, varItem)
Else
strAdd = strAdd & ";" & List12.Column(i, varItem)
End If
Next i
List14.RowSourceType = "value list"
List14.AddItem strAdd
strAdd = ""
Next varItem
I have being able to get code working to move items up and down within the listbox.
Code:
Dim sText As String
Dim iIndex As Variant
Dim selection() As Integer
Dim n, topSelection As Integer
' save the indexes of the selected items,
' they will be deselected after the first removal
For Each iIndex In List14.ItemsSelected
ReDim Preserve selection(0 To n)
selection(n) = iIndex
n = n + 1
Next
'loop through all the selected indexes
'this will also ensure you will only proceed if there is a selected item
For n = LBound(selection) To UBound(selection)
'save items text and items indexvalue
sText = List14.Column(0, selection(n))
If selection(n) <= topSelection Then 'index topSelection is top item which can't be moved up!
MsgBox ("Can not move item '" & sText & "' up any higher.")
topSelection = topSelection + 1
Else
'first remove item from old position
List14.RemoveItem selection(n)
'place item back on new position
List14.AddItem sText, selection(n) - 1
'change the index of the selected value to the new index (for reselection)
selection(n) = selection(n) - 1
End If
Next
'loop through the selection again to reselect
For n = LBound(selection) To UBound(selection)
List14.Selected(selection(n)) = True
Next
However, when the item is moved only the first of the 3 fields are visible. How do I get all three fields to be displayed in the new position?