Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: TLIstview Sort


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 2 - Last Post: Mar 15, 2016 1:18 AM Last Post By: Peter Gore
Peter Gore

Posts: 12
Registered: 9/29/06
TLIstview Sort  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 14, 2016 5:34 AM
Can someone give me an example of how to sort the items in a Fmx TLIst view. Nothing I've tried seems to work.

e.g.

function LVCompare(Right, Left: TFmxObject): Integer;
begin
result := CompareText(TListViewItem(Right).Text, TListViewItem(Left).Text);
end;

...
MyListview.Sort(LVCompare);

Does not work
Delphi 10

Linden ROTH

Posts: 467
Registered: 11/3/11
Re: TLIstview Sort  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 14, 2016 3:24 PM   in response to: Peter Gore in response to: Peter Gore
Peter Gore wrote:
Can someone give me an example of how to sort the items in a Fmx TLIst view. Nothing I've tried seems to work.

Does not work
Delphi 10


Need to sort the items

uses
  Generics.defaults;
 
procedure TFormXX.ButtonXClick(Sender: TObject);
var
  Comparer: IComparer< TListViewItem >;
 
begin
  Comparer := TDelegatedComparer< TListViewItem >.Create(
 
    function(const Left, Right: TListViewItem): Integer
    begin
      result := CompareText(Right.Text, Left.Text);
    end
    );
  ListView1.Items.Sort( Comparer );
end;


--
Linden
"Mango" was Cool but "Wasabi" was Hotter but remember it's all in the "source"
Peter Gore

Posts: 12
Registered: 9/29/06
Re: TLIstview Sort  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 15, 2016 1:18 AM   in response to: Linden ROTH in response to: Linden ROTH
Linden ROTH wrote:
Peter Gore wrote:
Can someone give me an example of how to sort the items in a Fmx TLIst view. Nothing I've tried seems to work.

Does not work
Delphi 10


Need to sort the items

uses
  Generics.defaults;
 
procedure TFormXX.ButtonXClick(Sender: TObject);
var
  Comparer: IComparer< TListViewItem >;
 
begin
  Comparer := TDelegatedComparer< TListViewItem >.Create(
 
    function(const Left, Right: TListViewItem): Integer
    begin
      result := CompareText(Right.Text, Left.Text);
    end
    );
  ListView1.Items.Sort( Comparer );
end;


--
Linden
"Mango" was Cool but "Wasabi" was Hotter but remember it's all in the "source"

Awesome - Thank you very much
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02