Help Passing TreeView to another form and then back

  • Thread starter dixiecanterbury
  • Start date
D

dixiecanterbury

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
 
N

Nicholas Paldino [.NET/C# MVP]

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

Stoitcho Goutsev \(100\)

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.
 

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

Top