Enable/Disable the DateTimePicker based on checkbox

3 posts, 0 answers
  1. Carisch
    Carisch avatar
    25 posts
    Member since:
    Aug 2007

    Posted 15 Jan 2011 Link to this post

    I have a DateTimePicker Control.  I have set the ShowCheckBox Property to True.  I would like this checkbox to enable/disable the datetimepicker based on weather it is checked or not.  I'm surprised it doesn't do this by default.  Nor is there any other property to set to allow this behavior.  I also can't find any event to hook into that would allow me to achieve the desired results.

    I did find through the smart tags how I could disable the two "parts" of the DateTimePicker (RadDateTimePickerArrowButtonElement, and RadMaskEditBoxElement) during design time.

    Another approach, I guess that works is to attached to the value changed event.  This way as soon as a user sets the value from null to something, the checkbox could be checked for them.  This allows them to have the correct checkbox state, without manually checking it themselves.

    Any help would be appreciated.


    Thanks, 
  2. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 15 Jan 2011 Link to this post

    Hello Brian,

    this should do what you are looking for.

    1: Register an event handler for the checkbox element (toggle state changed)
    AddHandler CType(Me.RadDateTimePicker1.DateTimePickerElement.Children(1).Children(0), RadCheckBoxElement).ToggleStateChanged, AddressOf RadDateTimPicker_ToggleStateChanged

    2: Disable / Enable the textbox item and arrow button depending on the toggle state
    Private Sub RadDateTimPicker_ToggleStateChanged(ByVal sender As Object, ByVal e As StateChangedEventArgs)
        Me.RadDateTimePicker1.DateTimePickerElement.TextBoxElement.Enabled = CType(sender, RadCheckBoxElement).ToggleState = Enumerations.ToggleState.On
        CType(Me.RadDateTimePicker1.DateTimePickerElement.Children(1).Children(1), RadDateTimePickerArrowButtonElement).Enabled = CType(sender, RadCheckBoxElement).ToggleState = Enumerations.ToggleState.On
    End Sub

    Hope that helps
    Richard
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 17 Jan 2011 Link to this post

    Hello,

    Did this help? If so please remember to mark as answer. If you need more informaton, let me know
    Thanks
    Richard
Back to Top