Home>

How to implement sorting speakers in ListView. By clicking on the name of the column?

  • Answer # 1

    RTFM.

    Method Parameters -the address of the comparison function (returning -1.0.1 for two elements), and an arbitrary number where you can transfer the column index, which is pressed.

    Function CustomSortProc (Item1, Item2: TlistItem; Paramsort: Integer): Integer; stdcall;
    Begin.
      If Paramsort= 0 THEN
        Result:= CompareText (Item1.Caption, Item2.Caption)
      ELSE.
        If Item1.Subitems.count >
    Paramsort-1 Then
        Begin.
          if item2.subitems.count >
    Paramsort-1 Then
            Result:= CompareText (Item1.Subitems [Paramsort-1], Item2.Subitems [Paramsort-1])
          ELSE.
            RESULT:= 1;
        End.
        ELSE.
          RESULT:= -1;
    end;
    Procedure TForm1.ListView1ColumnClick (Sender: Togject;
      Column: tlistcolumn);
    Begin.
      Listview1.customsort (@customSortProc, Column.Index);
    end;