Results 1 to 5 of 5

Thread: Listview sorting *Resolved*

  1. #1

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Resolved Listview sorting *Resolved*

    I found some code from kleinma (I think) for sorting a listview... Here is part of the code :

    Code:
    Private Sub lvDisks_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)
        Call ClearHeaderIcons(ColumnHeader.Index)
        Select Case ColumnHeader.Index
            Case 2, 3, 5, 6, 7, 9, 10, 11, 12, 13
                Select Case ColumnHeader.Icon
                    Case "down"
                        ColumnHeader.Icon = "up"
                        Call SortColumn(lvDisks, ColumnHeader.Index, sortDescending, sortString)
                    Case "up"
                        ColumnHeader.Icon = "down"
                        Call SortColumn(lvDisks, ColumnHeader.Index, sortAscending, sortString)
                    Case Else
                        ColumnHeader.Icon = "down"
                        Call SortColumn(lvDisks, ColumnHeader.Index, sortAscending, sortString)
                End Select
            Case 1, 4, 8
                Select Case ColumnHeader.Icon
                    Case "down"
                        ColumnHeader.Icon = "up"
                        Call SortColumn(lvDisks, ColumnHeader.Index, sortDescending, sortNumber)
                    Case "up"
                        ColumnHeader.Icon = "down"
                        Call SortColumn(lvDisks, ColumnHeader.Index, sortAscending, sortNumber)
                    Case Else
                        ColumnHeader.Icon = "down"
                        Call SortColumn(lvDisks, ColumnHeader.Index, sortAscending, sortNumber)
                End Select
        End Select
        
        Set SortIndex = ColumnHeader
    End Sub
    This works just fine, but that is when the user clicks on a column. How would I sort on form_load though? I tried calling the sub, but I couldn't get it to work. Any ideas?
    Last edited by manavo11; Dec 3rd, 2004 at 07:54 PM. Reason: Resolved


    Has someone helped you? Then you can Rate their helpful post.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Listview sorting

    You called it like this and it didnt work?
    Code:
    lvDisks_ColumnClick 2
    Maybe you can only sort when the lv is finished loading, like in another event,
    Form_Activate? Then disable it after first sort so it doesnt keep firing
    everytime its activated. Or maybe use a timer so it fires after 250 ms after
    its loaded?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Listview sorting

    I get a type mismatch with Call lvDisks_ColumnClick(2)...

    I kind of wanted to create a ColumnHeader As MSComctlLib.ColumnHeader but I couldn't...


    Has someone helped you? Then you can Rate their helpful post.

  4. #4
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Listview sorting

    Set a reference to a ColumnHeader and pass that to the event.

    Code:
    Dim oColumnHeader As MSComctlLib.ColumnHeader
    Set oColumnHeader = ListView1.ColumnHeaders(2)
    
    Call ListView1_ColumnClick(oColumnHeader)
    
    Set oColumnHeader = Nothing

  5. #5

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Listview sorting

    Quote Originally Posted by brucevde
    Set a reference to a ColumnHeader and pass that to the event.

    Code:
    Dim oColumnHeader As MSComctlLib.ColumnHeader
    Set oColumnHeader = ListView1.ColumnHeaders(2)
    
    Call ListView1_ColumnClick(oColumnHeader)
    
    Set oColumnHeader = Nothing
    Set oColumnHeader = ListView1.ColumnHeaders(2) is what I couldn't figure out... Thanks Bruce


    Has someone helped you? Then you can Rate their helpful post.

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