Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to rename directly in the TreeView node?

How to rename directly in the TreeView node?

Scheduled Pinned Locked Moved C#
tutorialquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sinosoidal
    wrote on last edited by
    #1

    Hi, Do you people know when you click once in a treeview node in explorer for example? We can then rename directly that item. What do i need to do in order to implement that? Thx, Nuno

    M N 2 Replies Last reply
    0
    • S sinosoidal

      Hi, Do you people know when you click once in a treeview node in explorer for example? We can then rename directly that item. What do i need to do in order to implement that? Thx, Nuno

      M Offline
      M Offline
      MoustafaS
      wrote on last edited by
      #2

      You may create a custom control that on the rename shortcut converts the node head to a textbox and take the text and set it . OR Handle the F2 shortcut for example, and pop a custom messagebox up, take the new name, and set the text to it.


      About : Islam
      About : Me

      1 Reply Last reply
      0
      • S sinosoidal

        Hi, Do you people know when you click once in a treeview node in explorer for example? We can then rename directly that item. What do i need to do in order to implement that? Thx, Nuno

        N Offline
        N Offline
        Nyanoba
        wrote on last edited by
        #3

        Here is some code, you can refer, string

        selectedNodeText;
        private void RenametoolStripMenuItem_Click(object sender, EventArgs e)
        {
        TreeNode node = this.treeView.SelectedNode as TreeNode;
        selectedNodeText = node.Text;
        this.treeViewTestplan.LabelEdit = true;
        node.BeginEdit();
        }

            void treeView\_AfterLabelEdit(object sender, System.Windows.Forms.NodeLabelEditEventArgs e)
            {
                TreeNode node = this.treeView.SelectedNode as TreeNode;
                this.treeViewTestplan.LabelEdit = false;
        
                if (e.Label.IndexOfAny(new char\[\] { '\\\\', '/', ':', '\*', '?', '"', '<', '>', '|' }) != -1)
                {
                    MessageBox.Show("Invalid StepName.\\n" +
                      "The step Name must not contain " +
                          "following characters:\\n \\\\ / : \* ? \\" < > |",
                      "step name Edit Error", MessageBoxButtons.OK,
                      MessageBoxIcon.Error);
                    return;
                }
                if (string.IsNullOrWhiteSpace(e.Label))
                {
                    MessageBox.Show("Step name is Invalid");
                    e.CancelEdit = true;
                    return;
                }
        

        string label = (!string.IsNullOrEmpty(e.Label) ? e.Label :selectedNodeText);
        if (null != e.Label)
        {
        (node.ExecutionObject as Step).Name = label;

                }
                
            }
        
            void treeView\_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
            {           
                if (e.KeyCode == Keys.F2)
                {
                    this.RenametoolStripMenuItem\_Click(this, null);
                }
            }
        
        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups