RadCheckBox Problem on Enter KeyPress

5 posts, 1 answers
  1. Kashif
    Kashif avatar
    66 posts
    Member since:
    Jan 2019

    Posted 30 Aug Link to this post

    Dear Admins

    I'm using Telerik UI for WinForms R2 2019 SP1.

    Facing a problem in using RadCheckBox. When focus is on the CheckBox, ]Enter KeyPress Changes its ToggleState.

    Then I Compare this behavior with Microsoft own CheckBox control, it was doing as required.

    The Toggle State of ChcekBox should changes when MouseClick or SpaceBar key press.

    My main requirement is to change the focus to next control on Enter Key Press.

     

  2. Answer
    Nadya
    Admin
    Nadya avatar
    116 posts

    Posted 02 Sep Link to this post

    Hello, Kashif,

    To achieve this behavior, you should create a new checkbox element which inherits from the RadCheckBoxElement and change the logic for the Enter key in the OnKeyDown event. You should create a new checkbox control which inherits from the RadCheckBox control as well, and override the CreateButtonElement method in order to return the new checkbox element. Please refer to the following example:

    public class MyCheckBoxElement : RadCheckBoxElement
    {
        protected override void OnKeyDown(KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                return;
            }
            base.OnKeyDown(e);
        }
     
        protected override Type ThemeEffectiveType
        {
            get
            {
                return typeof(RadCheckBoxElement);
            }
        }
    }
     
    public class MyCheckBox : RadCheckBox
    {
        protected override RadButtonElement CreateButtonElement()
        {
            return new MyCheckBoxElement();
        }
     
        public override string ThemeClassName
        {
            get
            {
                return typeof(RadCheckBox).FullName;
            }
        }
    }

    After creating the new MyCheckBox control, you can find it in the Toolbox. If it doesn't appear in the Toolbox you can add a [Toolbox(true)] attribute to MyCheckBox class. 

    I hope this helps. Should you have any other questions, I will be glad to help.

    Regards,
    Nadya
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Kashif
    Kashif avatar
    66 posts
    Member since:
    Jan 2019

    Posted 04 Sep in reply to Nadya Link to this post

    Thank you for Example. Its Working now.

    But i Think it is default behavior of CheckBox  for WIndows and Even for Linux Based Softwares.

    and change should be made in the Control itself..

     

  4. Nadya
    Admin
    Nadya avatar
    116 posts

    Posted 05 Sep Link to this post

    Hello Kashif,

    Thank you for your feedback, we will consider implementing this if we receive more request for it. Any suggestions are very useful for us when discussing the features that the control should offer by default. 

    Regards,
    Nadya
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  5. Kashif
    Kashif avatar
    66 posts
    Member since:
    Jan 2019

    Posted 05 Sep in reply to Nadya Link to this post

    Thanks you
Back to Top