[英]How to handle Right mouse click event for a Tree view
I would like to have an option as rename File if i select on a file of the treeview. 如果我在treeview的文件中选择,我想有一个选项作为重命名File。 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..
如果我右键单击鼠标,我希望有一个选项作为“重命名文件”,如果我选择该选项,我希望能够重命名它。
TreeNode.BeginEdit
方法使您可以将节点置于编辑模式(对于TreeView
控件, LabelEdit = true
)。
Add a Context Menu Strip to the form with a 'Rename' entry and set that to be the ContextMenuStrip
of the TreeView
使用“重命名”条目将上下文菜单条添加到窗体,并将其设置为
TreeView
的ContextMenuStrip
this.treeView1.ContextMenuStrip = this.contextMenuStrip1;
Then on the 'Rename' click event do your renaming, checking first that there is a TreeNode
selected 然后在“重命名”单击事件上进行重命名,首先检查是否选择了
TreeNode
private void renameToolStripMenuItem_Click(object sender, EventArgs e)
{
if (treeView1.SelectedNode != null)
{
// Do renaming
TreeNode node = treeView1.SelectedNode;
node.Text = "New Text";
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.