Navigating ADVTreeView

Hey Bruno,

How do I expand and focus on a node in ADVTreeView. My ADVTreeView has one column and is Collection based. I am using the latest source.

Starting from the root I want to select and focus on node S5 for the path: Audi\A5 Series\S5.

Thanks in advance,

John

You can either do this programmatically and via interaction, it's unclear however which you want to do. Via interaction, you would do something like this:

procedure TForm1.AdvTreeView1AfterExpandNode(Sender: TObject;
  ANode: TAdvTreeViewVirtualNode);
begin
  AdvTreeView1.FocusedNode := ANode.GetFirstChild.Node;
end;

Note that this code is simply for demonstration purposes, it does not take into account of there are children or not. The specific way you want to implement this will differ from the above implementation.

With the path: Audi\A5 Series\S5 want to programmatically navigate to final node: S5 expanding as we go. Starting from the root expand out to final node and set focus on it.

Using Virtual Method of TADVTreeView

You could do something like this:

procedure TForm22.Button1Click(Sender: TObject);
var
  n, p: TAdvTreeViewNode;
begin
  n := AdvTreeView1.FindNodeByTextAndColumn('S5', 0, True);
  if Assigned(n) then
  begin
    p := n.GetParent;
    while Assigned(p) do
    begin
      p.Expand;
      p := p.GetParent;
    end;

    AdvTreeView1.FocusedNode := n;
  end;
end;