Board index » delphi » Sorting TTreeView via data or imageindex property?

Sorting TTreeView via data or imageindex property?

Hi folks.

I want to being able to sort my TTreeNodes in a TTreeView so that
items with a low imageindex (or data index) is the first in the list
and the ones with a higher imageindex is further down in the list.

Like this:

Item1    (imageindex 1)
item2    (imageindex 1)
item3    (imageindex 1)
item4    (imageindex 2)
item5    (imageindex 3)

Working code will be appreciated .

-torsten

 

Re:Sorting TTreeView via data or imageindex property?


Hi folks.

I want to being able to sort my TTreeNodes in a TTreeView so that
items with a low imageindex (or data index) is the first in the list
and the ones with a higher imageindex is further down in the list.

Like this:

Item1    (imageindex 1)
item2    (imageindex 1)
item3    (imageindex 1)
item4    (imageindex 2)
item5    (imageindex 3)

Working code will be appreciated .

-torsten

Re:Sorting TTreeView via data or imageindex property?


In article <eiSY5.4482$0p2.266...@news000.worldonline.dk>, "torsten"

Quote
<tors...@inhouse.it> writes:
>I want to being able to sort my TTreeNodes in a TTreeView so that
>items with a low imageindex (or data index) is the first in the list
>and the ones with a higher imageindex is further down in the list.

function CompareNode(lParam1, lParam2, lParamSort: Longint): Integer stdcall;
begin
  Result := TTreeNode(LParam1).ImageIndex - TTreeNode(lParam2).ImageIndex;
  {-ve == LowerValue above HigherValue}
end;

 . . . and then

   TreeView1.CustomSort(@CompareNode, 0);

The second parameter is passed unchanged to the sort function for any purpose
you might want to pass it for (rather like the Tag property of an object).

This will sort siblings in accordance with the compare function.

Alan Lloyd
alangll...@aol.com

Other Threads