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..
Asked
Active
Viewed 1,257 times
2 Answers
2
The TreeNode.BeginEdit
method allows you to put a node in edit mode (given that LabelEdit = true
for the TreeView
control).

Fredrik Mörk
- 155,851
- 29
- 291
- 343
1
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";
}
}

Iain Ward
- 9,850
- 5
- 34
- 41
-
Instaed of giving some text can i prompt the user to save his own name – Developer Aug 28 '10 at 07:14
-
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 – Iain Ward Aug 28 '10 at 10:28