Click here to Skip to main content
15,880,796 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
HI I want to add checkbox in date time picker control.
e.g when someone check the checkbox current date & time
will be selected. Is it possible ? if yes pls help me
how to add checkbox in datetimepicker control
Posted

I have a form with two DateTimePicker controls. dtpDate has the Format property set to Long and dtpTime has the Format property set to Time and ShowUpDown set to True.

I created one check box chkDT but you could create a check box for each control.

VB
Private Sub chkDT_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkDT.CheckedChanged
        If chkDT.Checked = True Then
            dtpDate.Value = Now
            dtpTime.Value = Now
            dtpDate.Enabled = False
            dtpTime.Enabled = False
        Else
            dtpDate.Enabled = True
            dtpTime.Enabled = True
        End If
    End Sub


Hope this helps.
 
Share this answer
 
v2
Comments
Sandeep Mewara 1-Jul-10 0:48am    
Just corrected code formatting part.
DhavalG 11-Jul-10 6:13am    
Reason for my vote of 4
I think this is enough for my
requirement
Hi,

the System.Windows.Forms.DateTimePicker class has a property called "ShowCheckBox".
If you set this property to true, then you will have a checkbox inside your DateTimePicker.

This checkBox will then enable or disable the DateTimePicker.

Regards
 
Share this answer
 
Comments
[no name] 1-Jul-10 9:11am    
Yes, but that doesn't set it to current date and time.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900