Board index » delphi » TListView ImageList Sort

TListView ImageList Sort

I am trying to have a TListView sort the captions, and also group them
together by ImageIndex, so that all the items with ImageIndex=0 are
first (sorted alpha) and then all then Items with ImageIndex=1 are next
(alpha sorted) etc.  If anyone knows how I might implement this please
let me know.  Send all replies to: lea...@mail.utexas.edu

Thanks

 

Re:TListView ImageList Sort


David Turner <lea...@mail.utexas.edu> wrote in article
<326D7BE4.6...@mail.utexas.edu>...

Quote
> I am trying to have a TListView sort the captions, and also group them
> together by ImageIndex, so that all the items with ImageIndex=0 are
> first (sorted alpha) and then all then Items with ImageIndex=1 are next
> (alpha sorted) etc.  If anyone knows how I might implement this please
> let me know.  Send all replies to: lea...@mail.utexas.edu

> Thanks

Try something like this with TFileTree.CustomSort, or better if you can,
call this as you build up each level of the Tree by calling
TTreeNode.CustomSort.  The Smaller the number of nodes to sort the better.
Especially since the complexity of the sort is non-linear. :-

function CustomSortProc(Node1, Node2: TTreeNode; ParamSort: integer):
integer; stdcall;
Var Node1Index, Node2Index : Integer;
begin
  Node1Index := Node1.Index;
  Node2Index := Node2.Index;

  if (Node1Index = Node2Index) then
     Result := lstrcmp(PChar(Node1.Text),  PChar(Node2.Text))
  else if (Node1Index < Node2Index) then
     Result := -1
  else if (Node1Index > Node2Index) then
     Result := 1
  else
     Result := 0;
end;

Call this with :

MyTree.CustomSort(@CustomSortProc, 0);
MyTreeNode.CustomSort(@CustomSortProc, 0);

Hope this helps,

Gary.

Other Threads