• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 151
  • Last Modified:

2 TreeViews & problem.. selecting same treenode from both..

I have 2 treeviews. Both treeviews has exactly the same structure.
If i select one node from view 1, how can i retrieve the text of same node of view 2 ?

View 1 will be visible and view 2 hidden, just for filenames..


0
DjDMac
Asked:
DjDMac
  • 2
  • 2
  • 2
  • +1
1 Solution
 
LischkeCommented:
Mmmh, I'd say you have at least two possibilities. One is to determine enough information of the node in tree1 to navigate to the corresponding node in tree2. This would involve to retrieve the top level parent of the node and determining the its index. In the process of going up parent by parent you'd need to store the chain and traverse it down again to get the child indices of the nodes on the way down to the node in question.

A better solution, though, would be to store references between the trees in the nodes' data property. This mean node1 of tree one stores node1 of tree2 in its data property and vice versa. As both trees have the same structure I suppose you build them synchroniously. So crossreferencing the nodes is only a minimal additional step.

You should ask yourself, though, why you need two trees of the same structure! They are equal, so you could store them in one tree.

Ciao, Mike
0
 
sburckCommented:
I agree with Mike's ending comment - this is what the data property exists for - invisible data that the node references.  Data is a generic pointer type, just build a string, and point data at it.  If you need a structure, put all the strings into a string list, and have each pointer point to the item in the stringlist as you build it.
0
 
DjDMacAuthor Commented:
Ok.. so i can use the data property, but how can i save the data propertys to file ?

Example.. i have message topics in treeview.. messages with replys etc.

Then i have each message in simple text file. now i need to store each messages filename to the treeviews nodes data property and save and also load this whole treeview including those data-propertys.. how can i do this ?
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
sburckCommented:
I see what you're getting at, but I think I can see an easy solution.  Going back to the stringlist idea I gave, try this:

At save time, you must make sure that for a given order of the treeview, your stringlist is sorted the same.  Traverse the tree, and make sure that the root of the treelist is index[0] in the stringlist, the first item of the first node is [1], etc.  Then just do a Stringlist.savetofile.

At load time, just load the tree and the stringlist from the file, and traverse the tree in a for loop from 0, setting the data component to StringList.items[loopindex] for each node.
0
 
philipleighsCommented:
I agree that the data property of the nodes is the way to go here, but if you want a simple answer to your original question, then you could do this (given the content is identical):

TreeView2.Items[TreeView1.Selected.AbsoluteIndex].Selected := true;

You'd want to check that TreeView1.Selected is not nil beforehand.

Cheers,
Phil.
0
 
DjDMacAuthor Commented:
This is really the simplest answer..
However, I re-coded the whole program, but thanx anyway.. I like short and simple answers..
0
 
philipleighsCommented:
Oh, thanks for the nice surprise, 400 pts, yay!  ;-)

Cheers,
Phil.
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now