I use code such as this to clear out the values in several text boxes:
Private Sub RibbonButtonInsert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RibbonButtonInsert.Click
UpdateDataSource()
StudentsBindingSource.ResetBindings(True)
DatePickerDateOfBirth.Value = ""
RichEditBoxForeName.Focus()
StudentsBindingSource.AddNew()
End Sub
Because the date picker control did not clear out like the other controls did, I tried:
DatePickerDateOfBirth.Value = ""
but it does not clear out. Instead, I get an “InvalidCastException”.
Can you show me what coding I need to properly clear out the value in this data picker?
Actually you are not clearing it out, you are assigning a string value to it. and as it is a Date type, the assignment is wrong.
the assigned value must be a Date format, you can do this:
later you can check and if the value is equal to MinValue, then the date is not set.