Recent

Author Topic: Partially collapsed treeview  (Read 1051 times)

teresa

  • Newbie
  • Posts: 3
Partially collapsed treeview
« on: November 25, 2020, 05:54:16 am »
(I know I had this working 18 months ago but I forget how, don't have access to the code any more)

I have a TFreeview, which has two levels of nodes: people, and their children, like this

Adam
....Adam1
....Adam2
Ben
...Ben1
Charlotte
Denis
   Den1
...den2

I want the treeview to behave in two ways:

   -  1) when loaded to display just the top level nodes: Adam, Ben, Charlotte Denis.
   -  2) Then when (double or single-) clicking one of those, to expand just that node  Optionally, to also collapse any node that is already expanded, but I can live without that bit.

Some mix of properties and options solved this, but I can't find it now.

Any ideas?

Teresa

egsuh

  • Hero Member
  • *****
  • Posts: 1266
Re: Partially collapsed treeview
« Reply #1 on: November 25, 2020, 08:27:47 am »
I think what you want is the default behavior of treeview unless you set AutoExpand = true.

teresa

  • Newbie
  • Posts: 3
Re: Partially collapsed treeview
« Reply #2 on: November 25, 2020, 09:27:12 am »
Thanks, but if I st autoexpand false, the tree loads with only the root node visible.

Teresa

wp

  • Hero Member
  • *****
  • Posts: 11830
Re: Partially collapsed treeview
« Reply #3 on: November 25, 2020, 09:36:22 am »
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. var
  3.   node: TTreeNode;
  4. begin
  5.   node := TreeView1.Items.AddChild(nil, 'Adam');
  6.   TreeView1.Items.AddChild(node, 'Adam1');
  7.   TreeView1.Items.AddChild(node, 'Adam2');
  8.  
  9.   node := TreeView1.Items.AddChild(nil, 'Ben');
  10.   TreeView1.Items.AddChild(node, 'Ben1');
  11.  
  12.   node := TreeView1.Items.AddChild(nil, 'Charlotte');
  13.  
  14.   node := TreeView1.Items.AddChild(nil, 'Denis');
  15.   TreeView1.Items.AddChild(node, 'Denis1');
  16.   TreeView1.Items.AddChild(node, 'Denis2');
  17.   TreeView1.Items.AddChild(node, 'Denis3');
  18. end;  

teresa

  • Newbie
  • Posts: 3
Re: Partially collapsed treeview
« Reply #4 on: November 25, 2020, 09:10:04 pm »
Oh I see what has happened. This code I'm working with has a labeled "root" node, which it shouldn't have. Removing that makes things tidier and working.

Thanks for your help.

 

TinyPortal © 2005-2018