By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,827 Members | 2,155 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,827 IT Pros & Developers. It's quick & easy.

Help Passing TreeView to another form and then back

P: n/a
I have a tree view on a form and I need to pass that treeview to
another form keeping the state of the treeview (expanded nodes, etc).

After the treeview has been manipulated (added nodes, deleted nodes,
etc) I need to pass the treeview BACK to the original form.

Is there an easy way to do this?

Thanks,
DC

Mar 9 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
DC,

You could try passing the control to the form, and then setting the
Parent property to the form/control that you want to host it. Chances are
it will recreate the handle, but it should retain all of the state.

Then, when you pass the tree view back, you should be able to set the
Parent property back to the original form.

When you set the parent, however, it will remove the control from the
original form, so I don't know if that is acceptable. You might have to
create a new instance and pass that over if you want both views to be
updated at the same time.

What I would do is create a bitmap before you pass the treeview, and
show that where the treeview was on the original form while it is being
manipulated in the other form.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<di*************@alltel.net> wrote in message
news:11*********************@j33g2000cwa.googlegro ups.com...
I have a tree view on a form and I need to pass that treeview to
another form keeping the state of the treeview (expanded nodes, etc).

After the treeview has been manipulated (added nodes, deleted nodes,
etc) I need to pass the treeview BACK to the original form.

Is there an easy way to do this?

Thanks,
DC

Mar 9 '06 #2

P: n/a
Hi,

Did you try sompley to add the tree view to the second form's controls:

form2.Controls.Add(treeView);

This will remove the tree view from the current form and add it to the
form2. All expantions and selection should be preserved.

However I believe that the tree view should be only a representation of your
data, so you should move the data around not the tree view.
--

Stoitcho Goutsev (100)

<di*************@alltel.net> wrote in message
news:11*********************@j33g2000cwa.googlegro ups.com...
I have a tree view on a form and I need to pass that treeview to
another form keeping the state of the treeview (expanded nodes, etc).

After the treeview has been manipulated (added nodes, deleted nodes,
etc) I need to pass the treeview BACK to the original form.

Is there an easy way to do this?

Thanks,
DC

Mar 10 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.