TextBox with AcceptsReturn=true

8 posts, 0 answers
  1. Roar
    Roar avatar
    9 posts
    Member since:
    Jul 2012

    Posted 29 Aug 2014 Link to this post

    Hi,
    I have a DataForm with an EditTemplate where I have a multiline TextBox for editing text. I need to be able to insert new lines by pressing the Return Key. But when I do that, the Dataform gets Comitted. How can I prevent the DataForm's Commit Command to fire when users press the Return key inside the TextBox?
  2. Yoan
    Admin
    Yoan avatar
    1068 posts

    Posted 01 Sep 2014 Link to this post

    Hello,

    RadDataForm has built-in keyboard navigation that executes the CommitEdit command, when "Enter" is pressed. You can override its default behavior, by using a custom command provider. You can check the Keyboard Support help article that sheds some more light on the matter. For your convenience, I have prepared a sample project which demonstrates the approach.

    I hope it helps.

    Regards,
    Yoan
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Roar
    Roar avatar
    9 posts
    Member since:
    Jul 2012

    Posted 12 Sep 2014 in reply to Yoan Link to this post

    Thanks, I got this working now.

    Regards,
    Roar Bjørndal-Rasmussen
  5. Johannes
    Johannes avatar
    66 posts
    Member since:
    Dec 2012

    Posted 04 Feb 2015 Link to this post

    I also need parts of this in my RadDataForms so first thank you very much for the example.

    I try to make some additions because what I really want is that "Enter" and "Return" do not execute the same actions. If user hits "Return" DataForm should't do anything (except insert a new line in a multiline TextBox). But if user hits "Enter" I want the RadDataForm to execute commit no matter if Focus is in a multiline TextBox or a Combobox or any other DataFormField. Is this possible?

    Note: It seems that when pressing "Enter" OR "Return" args.Key is always of value "Return" which makes it impossible to differ them. Any suggestions?
  6. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1127 posts

    Posted 09 Feb 2015 Link to this post

    Hello,

    I believe that the difference between them is not distinguishable by the .Net framework. Both of the entries in the System.Windows.Input.Key enumeration have one and the same actual value.

    /// <summary>The Return key. </summary>
            Return = 6,
            /// <summary>The Enter key. </summary>
            Enter = 6,


    Regards,
    Ivan Ivanov
    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.

     
  7. Johannes
    Johannes avatar
    66 posts
    Member since:
    Dec 2012

    Posted 11 Feb 2015 in reply to Ivan Ivanov Link to this post

    Hello Ivan,

    You'e right. I read some more documentation and today "Return" should be seen as the same key as "Enter". I've changed my Commit key to Ctrl + Enter/Return and that's fine. Thanks for your help.
  8. Gregg
    Gregg avatar
    33 posts
    Member since:
    Sep 2007

    Posted 18 Mar 2015 in reply to Yoan Link to this post

    Hi Yoan,

    Does your sample project solve the OP's problem? That is, does it insert a new line in the TextBox, rather than commit the DataForm, when Return/Enter key is pressed? When I apply your sample to my project, I notice that the position of the cursor in the TextBox is simply moved to the end of the text when the Return/Enter key is pressed. Nothing else happens, i.e. no new line. That behavior seems to be what you have coded in your sample:

    TB.SelectionStart = TB.Text.Length;
    TB.Focus();


    I expected your sample to insert a new line instead. Am I missing something? How to achieve a new line in TextBox when Return/Enter key is pressed?

    Thank you.
  9. Yoan
    Admin
    Yoan avatar
    1068 posts

    Posted 23 Mar 2015 Link to this post

    Hello Gregg,

    The reason for this behavior is that I had set a fixed Height for the Textbox. If you remove that setting you will be able to insert a new line on pressing the Enter key. You can check this screencast for a reference. If you need further assistance on this, do not hesitate to contact me again.

    Regards,
    Yoan
    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 WPF is Visual Studio 2017 Ready