|
|
Список (ListBox) - Изменение порядка (сортировка) элементов списка
Private Sub ListResort(ctlList As Control, iDirection%)
Dim ArrList() As String
Dim sStartName As String, sEndName As String
Dim iPosStart As Integer, iPosEnd As Integer
Dim intRow%, sVal$, iListCount%, iColumnCount%, iColumn%
On Error GoTo ListResort_Err
iListCount = ctlList.ListCount
If ctlList.ListIndex = -1 Then Exit Sub
If iDirection = -1 Then
If ctlList.ListIndex = 0 Then Exit Sub
Else
If ctlList.ListIndex = ctlList.ListCount - 1 Then Exit Sub
End If
ReDim ArrList(-1 To iListCount - 1)
iColumnCount = ctlList.ColumnCount
For intRow = 0 To iListCount - 1
sVal = ""
For iColumn = 1 To iColumnCount
sVal = sVal & ";" & ctlList.Column(iColumn - 1, intRow)
Next iColumn
sVal = Mid(sVal, 2)
ArrList(intRow) = sVal
If ctlList.Selected(intRow) Then
iPosStart = ctlList.ListIndex
sStartName = sVal
iPosEnd = iPosStart + iDirection
For iColumn = 1 To iColumnCount
sEndName = sEndName & ";" & ctlList.Column(iColumn - 1, iPosEnd)
Next iColumn
sEndName = Mid(sEndName, 2)
End If
Next intRow
ArrList(iPosStart) = sEndName
ArrList(iPosEnd) = sStartName
sVal = Join(ArrList, ";")
sVal = Mid(sVal, 2)
ctlList.RowSource = sVal
ListResort_End:
On Error Resume Next
Exit Sub
ListResort_Err:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in Sub ListResort.", _
vbCritical, "Произошла ошибка!"
Err.Clear
Resume ListResort_End
End Sub
MSA-2007 и выше ( 39 kB) Пример
|
|