How to traverse a TTIWAdvTreeView

I have a tree view created that I would like to traverse the entire tree and process the checked items.  I cannot find example code for the TMS AdvTreeView of how to do that the most efficiently.


Could someone post a general example of that please?

Thanks in advance.

Hi,

You can use a recursive function to loop through all items of a TTIWAdvTreeView control.

Example:

var
  i: integer;
begin
  for i := 0 to TreeView1.Items.Count - 1 do
  begin

    //Check if the node (TreeView1.Items) is checked

    RetrieveChildNodes(TreeView1.Items);
  end;



procedure RetrieveChildNodes(Node: TAdvTreeNode);
var
  ExN: TAdvTreeNode;
begin
  if not Assigned(Node) then
    Exit;

  ExN := Node.getFirstChild;
  if Assigned(ExN) then
  begin
    while (ExN <> nil) do
    begin

      //Check if the node (ExN) is checked

      RetrieveChildNodes(ExN);
      ExN := ExN.getNextSibling;
    end;
  end;
end;


Thanks.  Works great.

Follow up question.


If I process the "checked" node and want to clear the check and redraw the control, what do I do?

I have tried the invalidate and repaintcontrol options and neither have any effect.

Thanks
Allen

I'm assuming you are using an async event to update the checked state of a node?
Calling Invalidate on the TIWAdvTreeView control should be sufficient.


Example:
  if not (TIWAdvTreeView1.SelectedNode = nil) then
  begin
    TIWAdvTreeView1.SelectedNode.Checked := true;
    TIWAdvTreeView1.Invalidate;
  end;

Bart Holvoet2014-07-03 03:05:30