This is my code
//Contextmenu
private void renameToolStripMenuItem_Click(object sender, EventArgs e)
{
string strOld = treeViewACH.SelectedNode.ToString();
treeViewACH.SelectedNode.BeginEdit();
}
//To show the context menu on the selected node
private void treeViewACH_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
if (treeViewACH.SelectedNode.Parent != null)
{
string strSwitch = treeViewACH.SelectedNode.Parent.Text;
switch (strSwitch)
{
case "FileHeader":
//string strOld = treeViewACH.SelectedNode.Text.ToString();
contextMenuStrip1.Show(treeViewACH, e.Location);
break;
}
}
else
{
// MessageBox.Show("Left clicked");
}
}
}
// To rename
private void treeViewACH_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
{
if (e.Label.IndexOfAny(new char[]{'\\',
'/', ':', '*', '?', '"', '<', '>', '|'}) != -1)
{
MessageBox.Show("Invalid tree node label.\n" +
"The tree node label must not contain " +
"following characters:\n \\ / : * ? \" < > |",
"Label Edit Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
e.CancelEdit = true;
return;
}
}