TreeView2 point to subtree of TreeView1?

P

.pd.

Hello, I'm new to C#, Windows programming, etc. I've had a good old
ferret around for an answer to this, and played quite a bit but I can't
get this working.

My app is an MDI with a Treeview on the parent form. The hierarchy I
have planned looks like this:

[database 1]
|
|
+-- Topic A
| |
| +-- Subtobic A1
| | |
| | +-- Idea 1
| | +-- Idea 2
| |
| +-- Subtopic B1
| | |
| ... +-- Subtopic B1A
|
+-- Topic B
|
|
|
+-- Topic C

So that ideas can be members of at least one topic.

To create an idea, I have a dialog with a 2nd treeview inside it and a
list box with a button to copy topic titles from the treeview to the
listbox (much like Outlook does its recipient list building).

Since the topic sub-tree of the bigger tree already exists, can I simply
point my 2nd treeview at the topic part of the big treeview and avoid
duplicating all the nodes?

Begging clemency if this is too stupid a question for you to allow me to
live.

Cheers,
..pd.
 
R

Robert Rossney

[explanation snipped]
Since the topic sub-tree of the bigger tree already exists, can I simply
point my 2nd treeview at the topic part of the big treeview and avoid
duplicating all the nodes?

Wouldn't that be nice? But no.

The TreeNode object knows too much about its context for it to have more
than one context. It contains a reference to its parent node (Parent) and
to the TreeView that contains it (TreeView). The situation you're
describing would create a TreeNode that had two different values for Parent
and two different values for TreeView. And it would break all of the
navigation properties (like NextNode and PrevNode).

The smart way to do what you're trying to do, probably, is to make the
object that you're trying to represent as a TreeNode capable of keeping
multiple TreeNode objects updated. So, for a simple example, you could
conceivably write a property handler like this:

public Text(string Text) {
set {
text = Text;
foreach (TreeNode node in treeNodes)
{
node.Text = Text;
}
}
}

Hope this helps.

Bob Rossney
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top