views:

41

answers:

2

I would like to have an option as rename File if i select on a file of the treeview. If i right click the mouse i would like to have an option as Rename file and if i select that i would like to able to rename it..

+1  A: 

Add a Context Menu Strip to the form with a 'Rename' entry and set that to be the ContextMenuStrip of the TreeView

this.treeView1.ContextMenuStrip = this.contextMenuStrip1;

Then on the 'Rename' click event do your renaming, checking first that there is a TreeNode selected

private void renameToolStripMenuItem_Click(object sender, EventArgs e)
{
      if (treeView1.SelectedNode != null)
      {
          // Do renaming
          TreeNode node = treeView1.SelectedNode;
          node.Text = "New Text";
      }
}
w69rdy
Instaed of giving some text can i prompt the user to save his own name
Dorababu
Yeah that was just an example, you can open a new form and get them to input it there or use @Fredrik's method above (which is a better way I think) and get them to enter it straight into the TreeNode
w69rdy
+2  A: 

The TreeNode.BeginEdit method allows you to put a node in edit mode (given that LabelEdit = true for the TreeView control).

Fredrik Mörk