-
Is there a way uning the listview control to sort all rows except for the first row? So when I click on a column it will sort all the data according to what is in that column but leave the first row alone. I got it to sort all the rows but not this way.
-
Here's a trick to do that.
This code first saves the first item and its subitems and then removes it.
After that it sorts the ListView and add the first row again.
Code:
Private Sub ListView1_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)
Dim item As ListItem
Dim subItems() As ListSubItem
Dim i%, iCount%
Set item = ListView1.ListItems(1)
iCount = item.ListSubItems.Count - 1
ReDim subItems(iCount)
For i = 0 To iCount
Set subItems(i) = item.ListSubItems(i + 1)
Next
ListView1.ListItems.Remove 1
ListView1.SortKey = ColumnHeader.Index - 1
ListView1.Sorted = True
ListView1.Sorted = False
Set item = ListView1.ListItems.Add(1, item.Key, item.Text, item.Icon, item.SmallIcon)
For i = 0 To iCount
With subItems(i)
item.ListSubItems.Add , .Key, .Text, .ReportIcon, .ToolTipText
End With
Next
End Sub
Good luck!
-
Thanks.. It worked great!