Modify TreeView like Text Editor.

1 Answer 104 Views
Treeview
Jay
Top achievements
Rank 1
Jay asked on 18 Jan 2023, 06:54 AM
hello.

I want to modify radTreeView like Text Editor.
I want to create a new node and enter Edit mode of a new node when I press Enter during Text Editing, and enter Node Edit mode when KeyDown in Node so that I can add text.

Please suggest how to do it.

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 18 Jan 2023, 09:49 AM
Hello, Jay,

The following help article gives additional information about the editing lifecycle in RadTreeView:
https://docs.telerik.com/devtools/winforms/controls/treeview/editing/editing-nodes 

I have prepared a sample code snippet demonstrating how to start the editing process when handling a key:

        public RadForm1()
        {
            InitializeComponent();

            this.radTreeView1.AllowEdit = true; 

            this.radTreeView1.KeyDown += RadTreeView1_KeyDown;
        }

        private void RadTreeView1_KeyDown(object sender, KeyEventArgs e)
        {
            if (this.radTreeView1.SelectedNode!=null)
            {
                this.radTreeView1.BeginEdit();
                if (this.radTreeView1.ActiveEditor!=null)
                {
                    this.radTreeView1.ActiveEditor.Value = e.KeyData.ToString();
                    TreeViewTextBoxEditor editor = this.radTreeView1.ActiveEditor as TreeViewTextBoxEditor;
                    if (editor!=null)
                    {
                        BaseTextBoxEditorElement el = editor.EditorElement as BaseTextBoxEditorElement;
                        el.TextBoxItem.SelectionStart = el.Text.Length;

                    }
                }
            }
        } 

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

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

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