'требуется ссылка MS Common Controls 6.0
Private Sub UserForm_Initialize()
Dim x, i&, j&
x = Range("A1").CurrentRegion.Value
With Me.ListView1
' .Sorted = True 'сортировка по 1-му столбцу (SortKey = 0)
With .ColumnHeaders
For j = 1 To UBound(x, 2)
.Add , "Key" & j, x(1, j), 50
Next j
End With
For i = 2 To UBound(x)
With .ListItems.Add(, , x(i, 1))
For j = 2 To 6
.ListSubItems.Add , , x(i, j)
Next j
End With
Next i
End With
End Sub
Private Sub ListView1_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)
With Me.ListView1
.Sorted = True
.SortKey = ColumnHeader.Index - 1 'сортирует как текст!
.SortOrder = IIf(.SortOrder = 1, 0, 1)
End With
End Sub
Private Sub ListView1_ItemClick(ByVal Item As MSComctlLib.ListItem)
Me.TextBox1.Value = Item.Index
Me.TextBox2.Value = Item.SubItems(2)
End Sub
|