is there any way to set the date picker on the windows form to null so it forces the user to set the date instead of setting it by default to current date
.NET Base Class Library
is there any way to set the date picker on the windows form to null so it forces the user to set the date instead of setting it by default to current date
Hi Jassim,
You can use Validating event to validate user's input in conjunction with ErrorProvider component.
Regards,
Oleh.
Hi Jassim,
You can't set it to null or specify blank date,month or year.Provided date must be more than DateTime.MinValue and less than DateTime.MaxValue otherwise exception will be raised.
If year, month or date will be set as blank(0) - exception will be raised also.
As for me optimal decision is to validate user input using validating event.
Regards,
Oleh.
but how can i validate if it's patient's age !
when the clerk has too many patiens waiting she will just ignore this field because it's already set to default which is current date which is valid for today's borned patient.
Hi Jassim,
In such case patience born date could not be validated.But You can use DateTimePicker container's validating event to get clerk's attention and check whether he had not forgot to set correct patience born date.
bool bClose = false;
private void datetimepickercontainer_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
if(!bClose)
{
string strWarning = "Ensure patience's born date is correct!";
errorProvider1.SetError(dateTimePicker1, strWarning);
MessageBox.Show(strWarning,"Warning",MessageBoxButtons.OK,MessageBoxIcon.Warning);
e.Cancel = true;
bClose = true;
}
}
Regards,
Oleh.