473,388 Members | 1,480 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

TreeView Tag and clone

I have TreeNodes in a TreeView, each contains unique data in its Tag section.
I am trying to 'clone' a TreeNode and then modify the tag data of the cloned
TreeNode. What I am seeing is that by modifying the Tag data of the cloned
TreeNode the original TreeNode's Tag data is also being modified with the
identical change.

Does the clone method not create a completely new data reference of the
original TreeNode? If not, how can I get a separate copy of the Tag data?

--
Steve
Nov 16 '05 #1
4 6242
Clone creates a shallow copy. The Tag property is of type object, a
reference type. When you change the object pointed to by the reference, all
references to that object see the changes. To change the object for your
new TreeNode, create a new object and assign it to the Tag property of the
new TreeNode.

HTH

DalePres
MCAD, MCDBA, MCSE

"Steve Teeples" <St**********@discussions.microsoft.com> wrote in message
news:9D**********************************@microsof t.com...
I have TreeNodes in a TreeView, each contains unique data in its Tag
section.
I am trying to 'clone' a TreeNode and then modify the tag data of the
cloned
TreeNode. What I am seeing is that by modifying the Tag data of the
cloned
TreeNode the original TreeNode's Tag data is also being modified with the
identical change.

Does the clone method not create a completely new data reference of the
original TreeNode? If not, how can I get a separate copy of the Tag data?

--
Steve

Nov 16 '05 #2
Thanks. I guess I'll need to create a routine that makes a copy of my object.

"DalePres" wrote:
Clone creates a shallow copy. The Tag property is of type object, a
reference type. When you change the object pointed to by the reference, all
references to that object see the changes. To change the object for your
new TreeNode, create a new object and assign it to the Tag property of the
new TreeNode.

HTH

DalePres
MCAD, MCDBA, MCSE

"Steve Teeples" <St**********@discussions.microsoft.com> wrote in message
news:9D**********************************@microsof t.com...
I have TreeNodes in a TreeView, each contains unique data in its Tag
section.
I am trying to 'clone' a TreeNode and then modify the tag data of the
cloned
TreeNode. What I am seeing is that by modifying the Tag data of the
cloned
TreeNode the original TreeNode's Tag data is also being modified with the
identical change.

Does the clone method not create a completely new data reference of the
original TreeNode? If not, how can I get a separate copy of the Tag data?

--
Steve


Nov 16 '05 #3
If your object doesn't contain other reference types, you could just use
object.Clone() on your object. But you will have to handle it from the
lowest level of reference types and work up.

DalePres

"Steve Teeples" <St**********@discussions.microsoft.com> wrote in message
news:F6**********************************@microsof t.com...
Thanks. I guess I'll need to create a routine that makes a copy of my
object.

"DalePres" wrote:
Clone creates a shallow copy. The Tag property is of type object, a
reference type. When you change the object pointed to by the reference,
all
references to that object see the changes. To change the object for your
new TreeNode, create a new object and assign it to the Tag property of
the
new TreeNode.

HTH

DalePres
MCAD, MCDBA, MCSE

"Steve Teeples" <St**********@discussions.microsoft.com> wrote in message
news:9D**********************************@microsof t.com...
>I have TreeNodes in a TreeView, each contains unique data in its Tag
>section.
> I am trying to 'clone' a TreeNode and then modify the tag data of the
> cloned
> TreeNode. What I am seeing is that by modifying the Tag data of the
> cloned
> TreeNode the original TreeNode's Tag data is also being modified with
> the
> identical change.
>
> Does the clone method not create a completely new data reference of the
> original TreeNode? If not, how can I get a separate copy of the Tag
> data?
>
> --
> Steve


Nov 16 '05 #4
I followed your suggestion and worked on this till quite late last night. I
now have routines that clone each object. I was fortunate that the arrays
within my objects use standard types so the clone() of the arrays went
smoothly. Again, thanks much!

"DalePres" wrote:
If your object doesn't contain other reference types, you could just use
object.Clone() on your object. But you will have to handle it from the
lowest level of reference types and work up.

DalePres

"Steve Teeples" <St**********@discussions.microsoft.com> wrote in message
news:F6**********************************@microsof t.com...
Thanks. I guess I'll need to create a routine that makes a copy of my
object.

"DalePres" wrote:
Clone creates a shallow copy. The Tag property is of type object, a
reference type. When you change the object pointed to by the reference,
all
references to that object see the changes. To change the object for your
new TreeNode, create a new object and assign it to the Tag property of
the
new TreeNode.

HTH

DalePres
MCAD, MCDBA, MCSE

"Steve Teeples" <St**********@discussions.microsoft.com> wrote in message
news:9D**********************************@microsof t.com...
>I have TreeNodes in a TreeView, each contains unique data in its Tag
>section.
> I am trying to 'clone' a TreeNode and then modify the tag data of the
> cloned
> TreeNode. What I am seeing is that by modifying the Tag data of the
> cloned
> TreeNode the original TreeNode's Tag data is also being modified with
> the
> identical change.
>
> Does the clone method not create a completely new data reference of the
> original TreeNode? If not, how can I get a separate copy of the Tag
> data?
>
> --
> Steve


Nov 16 '05 #5

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

Similar topics

0
by: Andre Viens | last post by:
Hello, I have a TreeView I'm using to navigate through various options shown in a ListView. I want to use the SelectedNode.Tag property to hold the items in my ListView. Everything is working...
3
by: Kelvin Leung | last post by:
Hi I use Drag and Drop between 2 TreeView Control under VB.Net But I found that it cannot work when I add sub-class for each node Is it drag and drop method cannot work when the node with...
3
by: Gary Dunne | last post by:
I'm writing an app that requires drag and drop operation between a ListView and a TreeView control. (The source is the ListView). During the drag drop operation I want to be able to detect the...
2
by: Steven | last post by:
Hi, I have created my own node (class MyNode : TreeNode) for a TreeView. To populate the treeview, i use something like MyNode newNode = new MyNode("Bla bla bla","0","1") for example. But, to...
3
by: PiotrKolodziej | last post by:
Hi How to copy treeview.Nodes from one treeview to another. Is this posible to do this in one line ? ( Calling some function )
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...
7
by: John Rogers | last post by:
I had given up on this for a while, but I am attempting it again. This is what i am using to store my treeview layout into a db, I am only using a few fields to make it easier to understand while...
1
by: =?Utf-8?B?QW5kcmV3?= | last post by:
I am trying to adapt some code that I have where I drag and drop from two treeview controls. Now I want to drag and drop from a listview to a treeview. Whatever I do does not work and I cannot find...
0
by: =?Utf-8?B?QW5kcmV3?= | last post by:
I have some code that I use to drag and drop from treeview to treeview, now I want to adapt the code to drag and drop from listview to treeview. I am having problems adapting the code nor can I...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...

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.