Prevent RadTreeView entering edit mode when clicking on selected node

1 Answer 29 Views
Treeview
Hayley
Top achievements
Rank 1
Hayley asked on 19 Aug 2022, 07:41 AM

Hello,

Is it possible to prevent RadTreeView entering edit mode when you click on a selected node?  We would still like nodes to be editable but only when the user presses F2 or when we programmatically enter edit mode.

Thanks,

Hayley

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 22 Aug 2022, 01:02 PM
Hello, Hayley,  

RadTreeView offers the Editing event which allows you to control whether the edit operation is allowed or not. You can cancel this event in order to prevent entering edit mode. Feel free to use the BeginEdit() method to initiate editing on the selected node. Additional information about the editing lifecycle is available in the following help article:
https://docs.telerik.com/devtools/winforms/controls/treeview/editing/editing-nodes 

I have prepared a sample code snippet for your reference demonstrating how to start editing after pressing F2 or programmatically:
        public RadForm1()
        {
            InitializeComponent();

            this.radTreeView1.AllowEdit = true;
            this.radTreeView1.Editing+=radTreeView1_Editing;
            this.radTreeView1.PreviewKeyDown+=radTreeView1_PreviewKeyDown;
        }

        private void radTreeView1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
        {
            if (e.KeyData == Keys.F2)
            {
                this.radTreeView1.Tag = "edit";
            }
        }

        private void radTreeView1_Editing(object sender, TreeNodeEditingEventArgs e)
        {
            if (this.radTreeView1==null)
            {
                e.Cancel = true;
            }
            this.radTreeView1.Tag = null;
        }

        private void radButton1_Click(object sender, EventArgs e)
        {
            this.radTreeView1.Tag = "edit";
            this.radTreeView1.BeginEdit();
        }

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Treeview
Asked by
Hayley
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or