Tab stop when unchecked

4 posts, 0 answers
  1. Jay
    Jay avatar
    2 posts
    Member since:
    Jan 2015

    Posted 22 Jul Link to this post

    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?

  2. Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 25 Jul Link to this post

    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.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Jay
    Jay avatar
    2 posts
    Member since:
    Jan 2015

    Posted 25 Jul in reply to Dimitar Link to this post

    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?

  5. Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 26 Jul Link to this post

    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.
Back to Top