access and modify a certain node in a tree view

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mbh1
    New Member
    • Mar 2009
    • 8

    access and modify a certain node in a tree view

    hi,
    ive created a certain tree view, which i want to modify (in run time)
    on a certain button click.
    how can i change a certain node label name and how can i change its image (assume i have images in a image list)

    thanks!
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Assuming your tree control is named "EventTree" this is how you make a new node
    Code:
                TreeNode mainNode = new TreeNode();
                mainNode.Name = "mainNode";
                mainNode.Text = DateTime.Now.ToShortDateString();
                EventTree.Nodes.Add(mainNode);
    To change an existing node:
    Make a new node
    Find the old node
    Set the old node to the new node you just made

    Comment

    • mbh1
      New Member
      • Mar 2009
      • 8

      #3
      how can i find the old one?
      every node has it own index?
      suppose i want to reach a certain node (a certain index) how can i do it?
      thanks

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        Read up on the TreeView control. The experiment a little: Its the best way to learn.

        A common technique is to just check each node recursively to see if it is the text you are looking for. HINT: foreach(TreeNod e tn in MyTreeView.Node s)

        Visual Studio has a built in search feature under the 'Help' menu that comes in handy for finding this stuff on MSDN. And if that is too dry to read, Google will show you a lot of other Tutorials and How-To's.

        Comment

        Working...