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..


DjDMacAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.