469,926 Members | 2,288 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,926 developers. It's quick & easy.

C# - Form: Modify TreeView Name during Runtime

3
Hey guys, i'm still working on that chat program, and i was wondering if there was a way to modify the name of already created nodes during runtime.

i know that you can create them but i don't know how to edit the name of created ones.

thanks.
Aug 8 '08 #1
3 5704
cloud255
427 Expert 256MB
Expand|Select|Wrap|Line Numbers
  1. node.name = "new name";
take note that the name of the node is not displayed, to change that use:

Expand|Select|Wrap|Line Numbers
  1. node.name = "display text";
the easiet way do do this kind of thing is to type the name of the control you want to edit followed by a "." and then just use intellisense...
Aug 12 '08 #2
roucha
3
there is nothing that is called "node" hence i can't do

node.name = "hello";

i have already tried this, thats why i'm asking here because i've tried everything that i knew.
Aug 16 '08 #3
cloud255
427 Expert 256MB
there is nothing that is called "node" hence i can't do

node.name = "hello";

i have already tried this, thats why i'm asking here because i've tried everything that i knew.
If the control exists at runtime, you can access its properties.

So somewhere in your code you create all these dynamic contols, after that, you can go:

Expand|Select|Wrap|Line Numbers
  1. Controls["controlName"].Text = "Display Text";
Whether you create the TreeView at runtime or not, you should have given it a name:

you can then loop through all your dynamically created nodes which live in this TreeView and access the "Text" property of the appropriate one:

Expand|Select|Wrap|Line Numbers
  1. foreach (TreeNode node in TreeView1.Nodes)
  2.             {
  3.                 if(node.Tag.Equals(somevalue))
  4.                 {
  5.                        node.Text = "New Value";
  6.                 }
  7.             }
You need to give some sort of unique value to each node you create, something meaningful which you can access, otherwise there is no way for you to distinguish between the nodes.

Good luck, hope this was helpful
Aug 16 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by John Bailo | last post: by
2 posts views Thread by serge calderara | last post: by
4 posts views Thread by Weinand Daniel | last post: by
1 post views Thread by Alexandru Nedelcu | last post: by
3 posts views Thread by Christian Hamel | last post: by
3 posts views Thread by avanti | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.