How to disable node renaming for TreeView in WinForms?

Is it possible to disable the option to switch to the "Rename" mode when clicking on the node tree?
I do not want to completely disable renaming, just not to do this by clicking node.

+5
source share
2 answers

You need to enable and disable the LabelEdit property if necessary:

    private void startLabelEdit() {
        treeView1.LabelEdit = true;
        treeView1.SelectedNode.BeginEdit();
    }

    private void treeView1_AfterLabelEdit(object sender, NodeLabelEditEventArgs e) {
        treeView1.LabelEdit = false;
    }

, , LabelEdit Windows. . , . , .

+4

, , LabelEdit, true.

BeforeLabelEdit , . F2:

        bool _allowNodeRenaming;

        private void treeView1_BeforeLabelEdit(object sender, NodeLabelEditEventArgs e)
        {
            if (!_allowNodeRenaming)
            {
                e.CancelEdit = true;
            }

            _allowNodeRenaming = false;
        }

        private void treeView1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F2)
            {
                _allowNodeRenaming = true;
                treeView1.SelectedNode.BeginEdit();
            }
        }
+6

All Articles