Set DateTimePicker control value to Null

I achieve this by handling the Binding Source that the control is binding to and enabling the ShowCheckBox property.

The .NET DateTimePicker doesn’t accept blank or NULL value. I’ve seen many posts online that extend the controller to accept NULL value like this one or some other posts to change the formatting to custom and switching back again.

So if you don’t feel like adding a new custom control to your project just handle the underlying data source.

DateTimePicker with CheckBoxesSince I had many of the DateTimePicker controls, I made one function that handles the Leave event of each one like so:

    Private Sub DateTimePicker_Leave(sender As System.Object, e As System.EventArgs) Handles Inv_OriginalDateTimePicker.Leave
        'Handle the DateTimePicker so when it is unchecked it saves Null value
        Dim dt As DateTimePicker = sender

        If Not dt.Checked Then
            'Get the current record
            Dim row = DirectCast(Me.PO_JobsBindingSource.Current, DataRowView)

            row(dt.DataBindings.Item("Value").BindingMemberInfo.BindingField.ToString) = DBNull.Value

        End If
    End Sub