This is a migrated thread and some comments may be shown as answers.

New Line in TreeViewTextBoxEditor

4 Answers 58 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
team igal
Top achievements
Rank 1
team igal asked on 12 Feb 2015, 04:06 PM
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!

4 Answers, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 17 Feb 2015, 08:50 AM
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.

 
0
team igal
Top achievements
Rank 1
answered on 01 Mar 2015, 08:00 AM
Thank you!!
0
team igal
Top achievements
Rank 1
answered on 02 Mar 2015, 03:29 PM
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);  
}
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 05 Mar 2015, 09:29 AM
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.

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