I have a DateTimePicker control on my WinForm with its CheckBox property enabled.
during the runtime when I want to select a date it does not show it in datetimepicker textbox, I know my code is correct cause the same code is working on the other form I have, but not in this one!
below is a snapshot of my code, any help is would be appreciated:
Private Sub btnInsert_Click(sender As Object, e As EventArgs) Handles btnInsert.Click
DateTimePicker1.Enabled = True
DateTimerPicker1.Checked = False
If DateTimePicker1.Checked = False Then
DateTimePicker1.CustomFormat = " "
DateTimePicker1.Format = DateTimePickerFormat.Custom
DateTimePicker1.Format = DateTimePickerFormat.Short
To handle change of that check box, you can use
Private Sub DateTimePicker1_ValueChanged(sender As Object, e As EventArgs) _ Handles DateTimePicker1.ValueChanged If Me.DateTimePicker1.Checked=True Then Me.DateTimePicker1.Format = DateTimePickerFormat.Short Else Me.DateTimePicker1.Format = DateTimePickerFormat.Custom Me.DateTimePicker1.CustomFormat = " " End If End Sub
In your code, you told it to don't show a date using
DateTimePicker1.CustomFormat = " ".
See the comments that I added to your code below:
DateTimerPicker1.Checked = False '<==== You set Checked to false If DateTimePicker1.Checked = False Then '<==== You told if not checked (it's not checked) DateTimePicker1.CustomFormat = " " '<==== Show space DateTimePicker1.Format = DateTimePickerFormat.Custom ....