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

Enable/Disable the DateTimePicker based on checkbox

2 Answers 574 Views
Calendar, DateTimePicker, TimePicker and Clock
This is a migrated thread and some comments may be shown as answers.
Carisch
Top achievements
Rank 1
Carisch asked on 15 Jan 2011, 04:58 PM
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 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 15 Jan 2011, 06:15 PM
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
0
Richard Slade
Top achievements
Rank 2
answered on 17 Jan 2011, 02:39 PM
Hello,

Did this help? If so please remember to mark as answer. If you need more informaton, let me know
Thanks
Richard
Tags
Calendar, DateTimePicker, TimePicker and Clock
Asked by
Carisch
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Share this question
or