List View - Sort by Clicking Header 
Author Message
 List View - Sort by Clicking Header

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.



Fri, 31 Jan 2003 03:00:00 GMT  
 List View - Sort by Clicking Header
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.


Quote:
> 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.



Fri, 31 Jan 2003 03:00:00 GMT  
 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.


Mon, 03 Feb 2003 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Sorting the content of list view on clicking column headers

2. List View click on header to sort date column

3. Display Bitmaps in Sub Items and column Headers of List View During Report View

4. sort a listview by column header click

5. ? 3014 Can't open any more tables - Click header to sort by column fails

6. Sorted a listview on header click

7. DBGrid Sorting by Clicking on the Header Row

8. List View Column Headers

9. Placing an image in a list view's column header

10. Placing an image in a list view's column header

11. slow list view sorting - help needed

12. List view and sorting

 

 
Powered by phpBB® Forum Software