I want to validate the DateTimePicker control in vb.net. I am using it for date of joining for the employee so i dont want the control to allow selection of future dates..only dates till the current date can be allowed to select. I have tried the following code:
Private Sub DateTimePickerDOJ_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePickerDOJ.ValueChanged
If DateTimePickerDOJ.Value > Date.Today Then
MessageBox.Show("You Cannot Select a Future Date!", "", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End Sub
The above code only displays the message correctly but its of no use becoz the future date is getting selected.
can anyone please help me out with dis problem?
You can use the DateTimePicker.MaxDate property to achieve that.
“Gets or sets the maximum date and time that can be selected in the control.”