Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting a listview by clicking different column headers

Status
Not open for further replies.

bjwade62

Programmer
Oct 31, 2002
15
US
I can't seem to find a way to sort a listview based on which column header is clicked. For instance when I click on a column header that is assigned to file names I want it to sort alphabetically, and when I click on a different column header I want it to sort by date. Another column header for time...

Can anyone help?

Thanks,
Bernie

 
Try this:
Private Sub ListView1_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)
With ListView1

If .SortOrder = lvwAscending Then
.SortOrder = lvwDescending
Else
.SortOrder = lvwAscending
End If

.SortKey = ColumnHeader.Index - 1
End With
End Sub
 
That works for text but not numbers such as dates and file sizes. Any other suggestions?

Thanks for replying,
Bernie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top