Checkbox ContainsFocus

1 Answer 38 Views
Form
Mark
Top achievements
Rank 2
Bronze
Bronze
Veteran
Mark asked on 29 Mar 2024, 11:14 AM

How can I tell if a CHECKBOX contains focus.  We have a specific set of keyboard requirements that if the user clicks the "ENTER" key, the next control should bet set focused, but not change the state of the checkbox.  Clicking the "ENTER" key does change the state.   When you are on a CheckBox, ContainsFocus doesn't seem to work.   So, what we would like to do, is if the CHECKBOX has focus, when the use clicks the "ENTER" key, it just moves to the next control in a tab order and not check the checkbox.  (We are trying to get the DateTimePicker to do the same thing)...

 


protected virtual void HandleKeyDownForForm(object sender, KeyEventArgs e)
{
   if (e.KeyData == Keys.Enter)
   {
      if (ntsRadDateTimePickerDob.ContainsFocus)
      {
         _dobHasNullValue = !ntsRadDateTimePickerDob.NullableValue.HasValue;
      }

      if (radCheckBoxActiveAbsentee.ContainsFocus)
      {
         _activeAbsenteeValue = radCheckBoxActiveAbsentee.IsChecked;
      }

      Control ctl = (Control)sender;
      ctl.SelectNextControl(ActiveControl, true, true, true, true);
   }
}

 

Any help would be greatly appreciated.

 

Thank You.

1 Answer, 1 is accepted

Sort by
0
Nadya | Tech Support Engineer
Telerik team
answered on 01 Apr 2024, 01:51 PM

Hello, Mark,

If I understand correctly, you would like to move to the next control when the Enter key is pressed without checking on the RadCheckBox. You can use the following code snippet to achieve your requirements. The provided gif file demonstrates the result on my end after pressing the Enter key. 

this.radCheckBox1.KeyDown += Handles_KeyDown;
this.radDateTimePicker1.KeyDown += Handles_KeyDown;

private void Handles_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyData == Keys.Enter)
    {
        if (radDateTimePicker1.ContainsFocus)
        {
            _dobHasNullValue = !radDateTimePicker1.NullableValue.HasValue;
        }

        if (radCheckBox1.ContainsFocus)
        {
            radCheckBox1.Checked = false;
            _activeAbsenteeValue = radCheckBox1.IsChecked;

        }

        SendKeys.Send("{TAB}");
    }
}

I hope this helps. Should you have any other questions do not hesitate to ask. 

Regards,
Nadya | Tech Support Engineer
Progress Telerik

A brand new ThemeBuilder course was just added to the Virtual Classroom. The training course was designed to help you get started with ThemeBuilder for styling Telerik and Kendo UI components for your applications. You can check it out at https://learn.telerik.com
Tags
Form
Asked by
Mark
Top achievements
Rank 2
Bronze
Bronze
Veteran
Answers by
Nadya | Tech Support Engineer
Telerik team
Share this question
or