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

Tab stop when unchecked

3 Answers 102 Views
Calendar, DateTimePicker, TimePicker and Clock
This is a migrated thread and some comments may be shown as answers.
Jay
Top achievements
Rank 1
Jay asked on 22 Jul 2016, 03:23 PM

I'm using the radDateTimePicker on a WinForms client (Q2 2016 release) with the ShowCheckBox property set to true and the Checked property set to false. The issue I'm having is that in that state, there seems to be no way to get the control to be a tab stop. I'm surmising that this is because it's trying to move focus not to the checkbox, but to the date, which is disabled because the checkbox is unchecked.

The MS VS date time picker control behaves as I'd expect (i.e. tabbing in stops at the checkbox so the user could, for example, tap on the space bar to check it and enable the date).

I've tried mucking about in the various UI Elements objects and their properties, primarily the RadCheckBoxElement and the RadCheckmark below that to no avail.

So, my question is simple - with the checkbox unchecked, how do I get the control to tabstop?

3 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 25 Jul 2016, 10:31 AM
Hello Jay,

Thank you for writing.

You should explicitly set the TabStop property, then you can enable the control when it gains the focus:
public RadForm1()
{
    InitializeComponent();
    radDateTimePicker1.ShowCheckBox = true;
    radDateTimePicker1.Checked = false;
  
    radDateTimePicker1.TabStop = true;
     
    radDateTimePicker1.GotFocus += RadDateTimePicker1_GotFocus;
}
  
private void RadDateTimePicker1_GotFocus(object sender, EventArgs e)
{
    if (radDateTimePicker1.Checked == false)
    {
        radDateTimePicker1.Checked = true;        
    }
}

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

Regards,
Dimitar
Telerik by Progress
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
0
Jay
Top achievements
Rank 1
answered on 25 Jul 2016, 12:59 PM

Ok, that's a partial solution, but I don't want the checkbox to become checked just because I enter into the field. I'd like it to work like the Microsoft supplied DTP and allow me to then hit the space bar to check it. Unfortunately, that doesn't work *unless* the checkbox has already been checked at least once.

 

Steps to reproduce are pretty simple. You just leave out the GotFocus code from your example (since in my case I don't want it to be checked) and run the program and tab into the field and you'll see that it takes focus, but it doesn't respond. However, if you click on the checkbox then uncheck it, move off the field and then tab back in, the space bar checks and un-checks via the space bar. So the behavior is somewhat inconsistent.

 

That being said, I'm willing to have code in my program that works around this bug but can't figure out what that code would be. The obvious and first thing I tried was adding in the GotFocus routine from your example, but added a Checked=false directly after the Checked=true, figuring that that might emulate the user clicking on it. That didn't work. So, I poked at it a few other ways and still didn't get anywhere.

 

So, any suggestions?

0
Dimitar
Telerik team
answered on 26 Jul 2016, 07:17 AM
Hello Jay,

In order to handle the space key and mimic the behavior of the standard .Net control you need to create a class that inherits RadDateTimePicker and override the OnKeyDown method:
class MyDateTimePicker : RadDateTimePicker
{
    protected override void OnKeyDown(KeyEventArgs e)
    {
        if (e.KeyData == Keys.Space)
        {
            this.Checked = !this.Checked;
        }
        else
        {
            base.OnKeyDown(e);
 
        }
    }
}

I hope this will be useful. 

Regards,
Dimitar
Telerik by Progress
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
Kelly
Top achievements
Rank 1
commented on 23 Feb 2022, 02:20 PM

The above solution only works if you want a tabstop at the control.  To get no tabstop you have to dig for a property that is not documented.  Like this...

      dtpLastActionDate.DateTimePickerElement.TextBoxElement.TextBoxItem.TabStop = false;

That's for a datetimepicker.  Here are other examples... a maskedtextbox and a textbox...

      mebTotalPieces.MaskedEditBoxElement.TextBoxItem.TabStop = false;
      txtSelectedFile.TextBoxElement.TextBoxItem.TabStop = false;

it is ridiculous that each of these controls, and I'm sure all the other controls, present a tabstop property that does nothing.

Dess | Tech Support Engineer, Principal
Telerik team
commented on 28 Feb 2022, 10:04 AM

Hello, Kelly,

Please have in mind that RadDateTimePicker internally hosts the standard MS TextBox which actually handles the focus when navigating with Tab. However, setting the RadDateTimePicker.TabStop property to false is just enough if you need to skip the control when pressing the Tab key. I have attached a sample project for your reference. Please give it a try with the latest version of the Telerik UI for WinForms suite.

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Tags
Calendar, DateTimePicker, TimePicker and Clock
Asked by
Jay
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Jay
Top achievements
Rank 1
Share this question
or