Expand a specific node

TeeTree VCL for Borland Delphi and C++ Builder.
Post Reply
McMClark
Newbie
Newbie
Posts: 50
Joined: Thu Apr 15, 2004 4:00 am

Expand a specific node

Post by McMClark » Thu Nov 02, 2006 4:08 pm

I am using a DBTree that is filled from a query. It has names of states and then counties underneath. Before getting to the form with the dbtree a user selects a state then the application takes them to the form with dbtree. I would like the dbtree to expand the node corresponding the state the user selected. Is there a way to search a tree and get the name and node number so that I can expand just that one node?

tom
Advanced
Posts: 211
Joined: Mon Dec 01, 2003 5:00 am
Contact:

Post by tom » Fri Nov 03, 2006 10:01 am

Hi,

The following code example should do the trick. This however assumes that the node text which is displayed is the same as the value in the dataset. If you are displaying some other information and want to search for the node with other information, then you can add this extra info in the OnNewShape event while creating the tree. You could for instance add an object or record or ... to the data property.

Code: Select all

procedure TForm1.Button5Click(Sender: TObject);
var t: integer;
begin
  for t := 0 to DBTree1.Shapes.Count - 1 do
  begin
    if SameText(DBtree1.Shape[t].SimpleText, Edit1.Text) then
    begin
      DBTree1.Shape[t].Expanded := True;
      break;
    end;
  end;
end;

Post Reply