
List View - Sort by Clicking Header
Here's an easier way. lstList is the name of the ListView control and
ColumnClick is an event triggered by clicking on the column header.
Private Sub lstList_ColumnClick(ByVal ColumnHeader As
ComctlLib.ColumnHeader)
lstList.SortKey = ColumnHeader.Index - 1
lstList.Sorted = True
End Sub
Quote:
> Use something like the following to set the sort type based on the
column:
> Private Sub flxDiagnostic_Click()
> With flxDiagnostic
> If (.MouseRow = 0) Then
> .RowSel = 0
> .Row = 0
> sortCol = .Col
> .ColSel = sortCol
> .Col = sortCol
> If (sortCol = 2) Then ' dprefix
> If (colSortMode(sortCol) = flexSortStringDescending) Then
> colSortMode(sortCol) = flexSortStringAscending
> Else
> colSortMode(sortCol) = flexSortStringDescending
> End If
> .Sort = colSortMode(sortCol)
> ElseIf (sortCol = 6) Then ' iprompt
> If (colSortMode(sortCol) = flexSortGenericDescending) Then
> colSortMode(sortCol) = flexSortGenericAscending
> Else
> colSortMode(sortCol) = flexSortGenericDescending
> End If
> .Sort = colSortMode(sortCol)
> ElseIf (sortCol > 7) Then ' points and expire and
delay
> If (colSortMode(sortCol) = flexSortNumericDescending) Then
> colSortMode(sortCol) = flexSortNumericAscending
> Else
> colSortMode(sortCol) = flexSortNumericDescending
> End If
> .Sort = colSortMode(sortCol)
> Else
> If (colSortMode(sortCol) = flexSortGenericAscending) Then
> colSortMode(sortCol) = flexSortGenericDescending
> Else
> colSortMode(sortCol) = flexSortGenericAscending
> End If
> .Sort = colSortMode(sortCol)
> End If
> .Sort = 0
> If (displayMode = 0) Then .Col = 1 Else .Col = 0
> End If
> End With
> End Sub
> colSortMode() is a form private array that keeps the sort order for
the last
> sort performed on each column; thus, the sort alternates betweem
ascending
> and descending per column.
> > Hi
> > List View
> > l have a number of difference types of columns headers eg Number,
String ,
> > Val and Date
> > l would like to Click on the header and sort by that column.
> > Thanks inadvance
> > Clive.
Sent via Deja.com http://www.deja.com/
Before you buy.