Board index » delphi » Advanced sorting of Treeview

Advanced sorting of Treeview

I need to do an advanced sorting of a treeview.
Something like this.

Those with image 1 sorted A-Z and
those with image 2 sorted A-Z.

Is that possible? I have asked this before but
haven't got any answer so I hope you can help me
now because I have the need and dont know exactly
where to start.
--
|_o_
   |  |         This message was brought to you by
Fredrik Larsson.
_/ \_            mail2fred @ hotmail.com (space spam
protect)

==================================================
=================
* Home          http://home3.swipnet.se/~w-33398/
* World of links
http://home3.swipnet.se/~w-33398/world/world.html
* Developers
* corner:
http://home3.swipnet.se/~w-33398/developer/
==================================================
=================

 

Re:Advanced sorting of Treeview


On Mon, 28 Jul 1997, Fredrik Larsson

Quote
<no_spam_mail2f...@hotmail.com_no_spam> wrote:
>I need to do an advanced sorting of a treeview.
>Something like this.

>Those with image 1 sorted A-Z and
>those with image 2 sorted A-Z.

You mean Z-A?

Quote
>Is that possible? I have asked this before but
>haven't got any answer so I hope you can help me
>now because I have the need and dont know exactly
>where to start.
>--

Lookup TTreeView.CustomSort.  You need to define a custom sort compare
function, e.g.,

function CustomSortProc(Node1, Node2: TTreeNode; Data: integer): integer;
stdcall;
begin
  // two items with different image? leave alone
  if Node1.ImageIndex<>Node2.ImageIndex then
     Result:=0
  else
  begin
    Result := AnsiStrIComp(PChar(Node1.Text), PChar(Node2.Text));
    if Node1.ImageIndex=2 then Result:=-Result;
  end;
end;

This procedure can then be used as a parameter to CustomSort to sort the
nodes of the tree view:

TreeView1.CustomSort(@CustomSortProc, 0);

-- luu

[cc'd by mail]

Other Threads