Jump to content

Criteria for Column sorting


Recommended Posts

Is there a way to have a criteria for listview sorting (eg when the user sorts a listview by one column, it checks the second column too and organizes based on both columns with the first column primary and the second column secondary)?

I'm working on a scheduler similar to TaskScheduler, but customized. I want one column to be the run time and the proceeding column to be for next run date.

Hope this makes sense. My current script is really long right now, so unless someone asks I'll refrain from posting it. I am lost on how to do the column criteria sorting though.

A decision is a powerful thing
Link to comment
Share on other sites

  • 1 month later...

You can use GUICtrlRegisterListViewSort() and in your sort routine compare more than one columns.

Look at my log_view project in my signature, here is sample for one column based user sorting:

GUICtrlRegisterListViewSort($ListView1, "LVSort")

Func LVSort($hWnd, $nItem1, $nItem2, $nColumn)
    ; Switch the sorting direction
    If $nColumn = $nCurCol Then
        If Not $bSet Then
            $nSortDir = $nSortDir * -1
            $bSet = 1
        EndIf
    Else
        $nSortDir = 1
    EndIf
    
    If $Done = 0 AND $nSortDir = 1 Then
        SetHeaderIcon($nColumn, 0)
        $Done = 1
    ElseIf $Done = 0 AND $nSortDir = -1 Then
        SetHeaderIcon($nColumn, 1)
        $Done = 1
    Endif

    $nCol = $nColumn

    $val1 = GetSubItemText($ListView1, $nItem1, $nColumn)
    $val2 = GetSubItemText($ListView1, $nItem2, $nColumn)

    ; osetreni nestandardnich sloupcu
    If $nColumn = 0 Then ; Datum a cas
        ; pozn: PrevedDatum() nepouzito kvuli optimalizaci rychlosti
;~         $val1 = PrevedDatum($val1) & StringMid($val1, 12)
;~         $val2 = PrevedDatum($val2) & StringMid($val2, 12)
        $val1 = StringMid($val1, 7, 4) & StringMid($val1, 4, 2) & StringLeft($val1, 2) & StringMid($val1, 12)
        $val2 = StringMid($val2, 7, 4) & StringMid($val2, 4, 2) & StringLeft($val2, 2) & StringMid($val2, 12)
    ElseIf $nColumn = 6 Then ; Velikost
        $val1 = Number($val1)
        $val2 = Number($val2)
    ElseIf $nColumn = 7 Then ; Rychlost
        $val1 = Number($val1)
        $val2 = Number($val2)
    EndIf

    $nResult = 0       ; No change of item1 and item2 positions

    If $val1 < $val2 Then
        $nResult = -1  ; Put item2 before item1
    ElseIf  $val1 > $val2 Then
        $nResult = 1   ; Put item2 behind item1
    EndIf
    
    Return $nResult * $nSortDir
EndFunc
Edited by Zedna
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...