New Line in TreeViewTextBoxEditor

5 posts, 1 answers
  1. team igal
    team igal avatar
    3 posts
    Member since:
    Feb 2010

    Posted 12 Feb 2015 Link to this post

    Hello Telerik team,

    I try to achieve the following behavior:
    I want to edit the content of a radtreenode by pressing f2.
    I set the editor type to be TreeViewTextBoxEditor, and it's property multiline to be true.
    Now I want my users to edit the content, and by pressing enter or key down make the edited content to start a new line, and continue the editing.

    The default behavior is that the editor is closed, and the next node down is being selected.

    How can I achieve the needed behavior?

    Thank you!
  2. Answer
    Dess
    Admin
    Dess avatar
    1601 posts

    Posted 17 Feb 2015 Link to this post

    Hello,

    Thank you for writing.

    By default, when pressing Enter key and the RadTreeView is in edit mode, the editor will be closed. However, I confirm that the user should be allowed to insert a new line. I have logged it in our feedback portal. You can track its progress, subscribe for status changes and add your vote/comment to it on the following link - feedback item.

    I have also updated your Telerik points.

    In order to achieve your goal you can create a derivative of the TreeViewTextBoxEditor and override the OnKeyDown method. Thus, when the Multiline property is set to true and you are pressing Ctrl+Enter, the editor will be kept active and a new line will be inserted:
    public Form1()
    {
        InitializeComponent();
     
        for (int i = 0; i < 10; i++)
        {
            radTreeView1.Nodes.Add(new string('w',i));
        }
     
        this.radTreeView1.AllowEdit = true;
        this.radTreeView1.ItemHeight = 40;
        this.radTreeView1.EditorRequired += radTreeView1_EditorRequired;        
    }
     
    private void radTreeView1_EditorRequired(object sender, TreeNodeEditorRequiredEventArgs e)
    {
        CustomTreeViewTextBoxEditor editor = new CustomTreeViewTextBoxEditor();
        editor.Multiline = true;
        e.Editor = editor;
    }
     
    public class CustomTreeViewTextBoxEditor : TreeViewTextBoxEditor
    {
        protected override void OnKeyDown(KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter &&
                e.Modifiers == Keys.Control &&
                this.Multiline)
            {
                return;
            }
            base.OnKeyDown(e);
        }
    }
     
    private void radTreeView1_NodeFormatting(object sender, TreeNodeFormattingEventArgs e)
    {
        e.NodeElement.ContentElement.TextWrap = true;
    }


    I hope this information helps. Should you have further questions, I would be glad to help.

    Regards,
    Dess
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for WinForms is Visual Studio 2017 Ready
  4. team igal
    team igal avatar
    3 posts
    Member since:
    Feb 2010

    Posted 01 Mar 2015 in reply to Dess Link to this post

    Thank you!!
  5. team igal
    team igal avatar
    3 posts
    Member since:
    Feb 2010

    Posted 02 Mar 2015 in reply to team igal Link to this post

    I tought that only Enter will work the same - if I change the condtion to the code below.
    However I see that when I do that, and press Enter, nothing happens - nor the editor closes, nor a new line started. Am i doing something wrong?
    protected override void OnKeyDown(KeyEventArgs e) 
    {
           if  (e.KeyCode == Keys.Enter && this.Multiline)  
           {     
               return;     
           }      
           base.OnKeyDown(e);  
    }
  6. Dess
    Admin
    Dess avatar
    1601 posts

    Posted 05 Mar 2015 Link to this post

    Hello,

    Thank you for writing back.

    By default, when the TreeViewTextBoxEditor.Multiline property is set to true, you can insert a new line by pressing Ctrl+Enter keys. If you change the condition in the TreeViewTextBoxEditor.OnKeyDown method you stop the basic logic for closing the editor when pressing Enter key. Additionally, a new line is not inserted as the AcceptsReturn property has false as default value. In the EditorRequired event you should set it to true:
    private void radTreeView1_EditorRequired(object sender, TreeNodeEditorRequiredEventArgs e)
    {
        CustomTreeViewTextBoxEditor editor = new CustomTreeViewTextBoxEditor();
        editor.Multiline = true;
        editor.AcceptsReturn = true;
        e.Editor = editor;
    }
     
    public class CustomTreeViewTextBoxEditor : TreeViewTextBoxEditor
    {
        protected override void OnKeyDown(KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter &&
              //  e.Modifiers == Keys.Control &&
                this.Multiline)
            {
                return;
            }
            base.OnKeyDown(e);
        }
    }

    I hope this information helps. If you have any additional questions, please let me know.

    Regards,
    Dess
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
UI for WinForms is Visual Studio 2017 Ready