[Lazarus] Strange Alphasort in ListView

Valdas Jankūnas zmuogs at gmail.com
Tue Apr 14 16:55:47 CEST 2015


2015.04.14 16:22, Vojtěch Čihák rašė:
> I understand. Method Sort; is protected (as it is in Delphi).
>
> You have probably no other choice than do
>
>   ListView1.SortDirection:=sdDescending;
>   ListView1.SortDirection:=sdAscending;
>
> which works but it is unefficient, sorting is done twice.
>
> I tried:
>   ListView1.BeginUpdate;
>   ListView1.SortDirection:=sdDescending;
>   ListView1.EndUpdate;
>   ListView1.SortDirection:=sdAscending;but it doesn't help, sorting is
> still done twice (at least on Qt).ListView has some flags to avoid
> sorting but those flags are private.V.
>

Thanks for mentioning protected Sort procedure. So I come to "dirty" 
solution:

  - create helper class:

type
   THack = class(TListView)
   public
      procedure Trigger_sort;
   end;

  - implement "Trigger_sort":

procedure THack.Trigger_sort;
begin
     Sort;
end;

  - now when to trigger sort with current settings is needed then execute:

THack(ListView1).Trigger_sort;


  Works for me (at least in Qt (Linux) and Win (Windows7)).



-- 
   Valdas Jankūnas




More information about the Lazarus mailing list