VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



This routine automatically sorts ListView controls in asc or dsc order when a column header is clic

by Wade Reynolds (3 Submissions)
Category: Custom Controls/Forms/Menus
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Tue 25th April 2000
Date Added: Mon 8th February 2021
Rating: (1 Votes)

This routine automatically sorts ListView controls in asc or dsc order when a column header is clicked. ListView control should be in report

Rate This routine automatically sorts ListView controls in asc or dsc order when a column header is clic



Follow these simple steps and use the included code:

1. Include a ListView control(s) in your form(s) and set
   the ListViews View property to 3 - lvwReport.



2. Place the following code in the ListView controls 
   ColumnClick event:


lvSortByColumn ListView1, ColumnHeader


   NOTE: replace ListView1 with the name of your
   ListView control.



3. Place the following code in a module:


Public Sub lvSortByColumn(theLV As ListView, theCol As MSComctlLib.ColumnHeader)

  Select Case theCol.Tag
  
    Case "Asc"
    theLV.SortOrder = lvwDescending
    theLV.SortKey = theCol.Index - 1
    theCol.Tag = "Dsc"
  
    Case "Dsc"
    theLV.SortOrder = lvwAscending
    theLV.SortKey = theCol.Index - 1
    theCol.Tag = "Asc"

    Case Else
    theLV.SortOrder = lvwAscending
    theLV.SortKey = theCol.Index - 1
    theCol.Tag = "Asc"
    
  End Select

End Sub



4. Finished!


When any column header is clicked, the contents
of the ListView control will be sorted by that
column in ascending order. If the same column is 
clicked a second time, it is resorted by that
column in descending order.


Have Fun!


Download this snippet    Add to My Saved Code

This routine automatically sorts ListView controls in asc or dsc order when a column header is clic Comments

No comments have been posted about This routine automatically sorts ListView controls in asc or dsc order when a column header is clic. Why not be the first to post a comment about This routine automatically sorts ListView controls in asc or dsc order when a column header is clic.

Post your comment

Subject:
Message:
0/1000 characters