Page 1 of 1

Expand a specific node

Posted: Thu Nov 02, 2006 4:08 pm
by 9337074
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?

Posted: Fri Nov 03, 2006 10:01 am
by Tom
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;