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 optio开发者_如何学运维n as Rename file and if i select that i would like to able to rename it..
The TreeNode.BeginEdit
method allows you to put a node in edit mode (given that LabelEdit = true
for the TreeView
control).
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";
}
}
精彩评论