I have two DateTimePickers dtpDateFrom and dtpDateTo.
I already coded a conditional statement that if dtpDateTo is earlier than dtpDateFrom via their ValueChanged event, I would get an error message, but it still applies the change.
Example:
Try to use the Validating event for the control. In your code where your validation fails put in e.cancel = true
Private Sub dtpDateFrom_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles dtpDateFrom.Validating
If dtpDateFrom.Value > dtpDateTo.Value Then
Messagebox.show("From date must be less than To date")
e.Cancel = True 'Validation failed.
End If
End Sub
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With