Results 1 to 3 of 3

Thread: listview sorting

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2000
    Posts
    114
    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.

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    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!

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2000
    Posts
    114
    Thanks.. It worked great!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width