473,471 Members | 1,737 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

ByVal TreeView Modifies Original?

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

Mar 18 '07 #1
2 1440
ca*****@gmail.com <ca*****@gmail.comwrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Mar 18 '07 #2
On Mar 18, 4:10 pm, Jon Skeet [C# MVP] <s...@pobox.comwrote:
casM...@gmail.com <casM...@gmail.comwrote:
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.
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.
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.

--
Jon Skeet - <s...@pobox.com>http://www.pobox.com/~skeet Blog:http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


Ok, thank you for your help Jon :)

Mar 19 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

42
by: lauren quantrell | last post by:
So many postings on not to use the treeview control, but nothing recently. Is it safe to swim there yet with Access 2000-Access 2003?
3
by: Steve Richter | last post by:
in windows explorer, the nodes immed under the "my computer" root node appear with a minimum of indenting ( the +/- square is directly underneath the root node ). In the .NET TreeView control the...
8
by: JJBean | last post by:
Hi All, How do I create a custom paint treeview control or an owner drawn treeview control ? Any tutorials on this anywhere? Thanks, JJBean
0
by: | last post by:
This is ugly, but.... If you switch the TreeView's font to a fixed-space (i.e., NOT proportional) font, such as Courier New, your original work-around of adding spaces as appropriate will work....
11
by: John Pass | last post by:
Hi, In the attached example, I do understand that the references are not changed if an array is passed by Val. What I do not understand is the result of line 99 (If one can find this by line...
1
by: musosdev | last post by:
Hi guys I was using the Microsoft.Web.UI.WebControls extra namespace in my application to provide me with a TreeView control. I was using specifically ..GetNodeFromIndex(), SelectedNodeIndex and...
2
by: dixiecanterbury | last post by:
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,...
1
by: Victor Rodriguez | last post by:
Is there a way that I can have a client side event like oncontextmenu="showfunction();" on each node? thanks, Victor
0
by: drop | last post by:
Hi, I am using a Treeview and I'd like to know what is the best way to refresh the children of a specific node in the treeview. I already do that using full postback, but this sends back the...
2
by: casManG | last post by:
I am working on a small project that uses the treeview control in .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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.