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

TreeView Tag and clone

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.