4

Everytime when I start my program DateTimePicker automatically shows todays date and time. How can I stop this ? How can I make it blank ?

I have a DOB DateTimePicker. For some users I don't know their DOB so I would like the DateTimePicker to show null or empty field.

Failed_Noob
  • 1,347
  • 18
  • 51
  • 67
  • This is really two questions in one - setting the value of the DateTimePicker is actually quite easy. Making it blank however is a little trickier. See this previous question http://stackoverflow.com/questions/846395/how-can-i-make-a-datetimepicker-display-an-empty-string – David Hall Apr 26 '11 at 16:23

7 Answers7

5

Set DateTimePicker.CustomFormat = " " Make sure there is a space. This will show up as a blank space.

I used a DataRowView drv = DBBindingSource(DB). along with a control statement to set null when needed.

if(drv.Row["DOB"] == DBNull.Value)
{
  DateTimePicker.CustomFormat = " ";
}
else
{
  DateTimePicker.CustomFormat = "dd MMMM yyyy";
}
seeSharper
  • 61
  • 1
  • 2
2

I don't think there is a way to allow it to be blank but you could use the ShowCheckBox and Checked properties set to true. The DateTimePicker will then have a checkbox in addition to the date dropdown. The date dropdown is disabled when not checked. This allows you to have a 'no value' or null for the DOB when the checkbox is not checked.

TKTS
  • 1,261
  • 1
  • 11
  • 17
1

See this CodeProject article on a Nullable DateTimePicker. It inhertis from DateTimePicker.

Olivier Jacot-Descombes
  • 104,806
  • 13
  • 138
  • 188
1

Use this :

Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
    DateTimePicker1.Value = DateTimePicker1.Value.Today
End Sub
Ria
  • 10,237
  • 3
  • 33
  • 60
0

if you are talking about datetimepicker from Trent Richardson, have a look at this thread https://stackoverflow.com/a/12645192/551811

basically, set the inputbox value in the onClose event.

$('input.datetime').datetimepicker({
        onClose: function (value) {
                        $('input.datetime').val(value);
                    }
     });
Community
  • 1
  • 1
BraveNewMath
  • 8,090
  • 5
  • 46
  • 51
0

my solution:

Public Sub ClearDatePicker(ByVal DatePicker As DateTimePicker)

DatePicker.CustomFormat = " "

DatePicker.Format = DateTimePickerFormat.Custom

End Sub

then the datetimepicker will be displayed empty.

Nazik
  • 8,696
  • 27
  • 77
  • 123
alon
  • 1
0

Set it's Value property to the date you want.

Akram Shahda
  • 14,655
  • 4
  • 45
  • 65