ByVal TreeView Modifies Original?

  • Thread starter Thread starter casManG
  • Start date Start date
C

casManG

I am working on a small project that uses the treeview control in
vb.net 2003. I have a tree view that I am sending to a sub in order to
iterate through the nodes.

Public Sub test (ByVal inTreeView as Tree View)

But, the thing I want to do with the inTreeView requires me to expand
all the nodes before I iterate. The problem is that when the sub is
complete, the original tree view on my form ends up with all of the
nodes expanded I had hoped that sending it to my sub "ByVal" would
make a copy that I could mess around with without effecting the
original. I also tried creating a new treeview and assigning the
inTreeView to it, then doing my stuff:

dim TestTree as new TreeView
TestTree = inTreeView

but no matter what the source treeview always gets expanded when I do
an expandall TestTree.ExpandAll()

Can anyone tell me how to get a duplicate of a treeview in a way that
I can expandall and not effect the source object?

Thanks
cas
 
I am working on a small project that uses the treeview control in
vb.net 2003. I have a tree view that I am sending to a sub in order to
iterate through the nodes.

Public Sub test (ByVal inTreeView as Tree View)

But, the thing I want to do with the inTreeView requires me to expand
all the nodes before I iterate. The problem is that when the sub is
complete, the original tree view on my form ends up with all of the
nodes expanded I had hoped that sending it to my sub "ByVal" would
make a copy that I could mess around with without effecting the
original. I also tried creating a new treeview and assigning the
inTreeView to it, then doing my stuff:

dim TestTree as new TreeView
TestTree = inTreeView

but no matter what the source treeview always gets expanded when I do
an expandall TestTree.ExpandAll()

Yes. You need to understand what it means to pass a reference by value.
See http://pobox.com/~skeet/csharp/parameters.html - it talks in C#
terms, but if you understand that the C# default is "ByVal" and "ref"
corresponds to "ByRef" it should still be useful.
Can anyone tell me how to get a duplicate of a treeview in a way that
I can expandall and not effect the source object?

You'll need two completely separate object, which should have
completely different objects underneath, I strongly suspect (i.e. they
won't actually share nodes).

Unfortunately TreeView doesn't provide a Clone method - I suspect
you'll have to create a new TreeView and then populate it by traversing
the "old" one and adding nodes with the same values to the new
TreeView.
 
Yes. You need to understand what it means to pass a reference by value.
Seehttp://pobox.com/~skeet/csharp/parameters.html- it talks in C#
terms, but if you understand that the C# default is "ByVal" and "ref"
corresponds to "ByRef" it should still be useful.


You'll need two completely separate object, which should have
completely different objects underneath, I strongly suspect (i.e. they
won't actually share nodes).

Unfortunately TreeView doesn't provide a Clone method - I suspect
you'll have to create a new TreeView and then populate it by traversing
the "old" one and adding nodes with the same values to the new
TreeView.



Ok, thank you for your help Jon :)
 
Back
Top