Board index » delphi » Link the treenodes item in one treeview to another treeview

Link the treenodes item in one treeview to another treeview

I am trying to link the contents(ttreenodes) of one treeview to
another and have the second automatically update when the first
treeview is modified.  I can do this if I constant set:
treeview1.items:=treeview2.items
every time treeview1 is modified.  This appears to act as a copy
of some sort because if I only set this once it never updates
the second treeview.  Since treeview.items is a pointer to
treenodes I thought the above statement would just reassign
the second treeview's treenodes pointer.  Do I need to call
an event for the second treeview to repaint every time the
first treeview is modified?  I don't understand why this doesn't
work.  Help.

 

Re:Link the treenodes item in one treeview to another treeview


U?ytkownik "CJ" <Chris.l.John...@alcatel.com> napisa3 w wiadomo?ci news:3c3602af$1_1@dnews...

Quote
> I am trying to link the contents(ttreenodes) of one treeview to
> another and have the second automatically update when the first
> treeview is modified.  I can do this if I constant set:
> treeview1.items:=treeview2.items
> every time treeview1 is modified.  This appears to act as a copy
> of some sort [...]

Exactly.

In TCustomTreeView Items is a property fefined as follows:

===========
property Items: TTreeNodes read FTreeNodes write SetTreeNodes;

procedure TCustomTreeView.SetTreeNodes(Value: TTreeNodes);
begin
  Items.Assign(Value);  {i.e. FTreeNodes.Assign(Value)}
end;
===========

So in your case each TTreeView object maitains its own items.
When you make the assignment the items from on object are
copied to the other (by Assign method) but the pointer itself
remains unchanged.

You can place the assignment in the OnChange event handler,
however this may slow down the program significantly, I'm afraid.

--
Zbigniew Lipinski
z...@webmedia.pl
http://www.webmedia.pl/zl1

Re:Link the treenodes item in one treeview to another treeview


Quote
>You can place the assignment in the OnChange event handler,
>however this may slow down the program significantly, I'm afraid.

>--
>Zbigniew Lipinski

I agree with your suggestion, but if the performance hit is too great I
would suggest creating another TTreeView in which SetTreeNodes does not use
the Assign method.

Christopher Weaver

Other Threads