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
2010-08-27 09:54:07
Instaed of giving some text can i prompt the user to save his own name
Dorababu
2010-08-28 07:14:51
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
2010-08-28 10:28:05
+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
2010-08-27 10:20:18