[英]Raise validating event on datepicker c# Winforms
我有2個datepickers。 一個有發票,一個有到期日。 我可以在明天選擇發票的日期。 但是當我繼續填寫控件時,它可能只是在今天離開截止日期。 這給出了沒有觸發duedate事件的場景,因為我沒有輸入它。 現在,我不希望用戶的截止日期小於實際發票日期,但由於“截止日期”的事件未被觸發,我無法真正驗證這一點。
誰能告訴我如何通過代碼觸發驗證事件?
這是我目前的情景:
private void dpInvoiceDate_Validating(object sender, CancelEventArgs e)
{
// Convert the dp invoice date + hour to only date
var dateAndTime = Convert.ToDateTime(dpInvoiceDate.Text);
var date = dateAndTime.Date;
if (!InputChecks.IsGeldigeDatum(DateTime.Now.Date, Convert.ToDateTime(date)))
{
errorProvider1.SetError(dpInvoiceDate, "Invoice date can not be in the past");
e.Cancel = true;
}
else
{
errorProvider1.SetError(dpInvoiceDate, "");
}
}
private void dpDueDate_Validating(object sender, CancelEventArgs e)
{
// Convert the dp invoice date + hour to only date
var dateAndTime = Convert.ToDateTime(dpDueDate.Text);
var date = dateAndTime.Date;
var dateAndTimeInvioceDate = Convert.ToDateTime(dpInvoiceDate.Text);
var dateInvoiceDate = dateAndTimeInvioceDate.Date;
if (date < dateInvoiceDate)
{
errorProvider1.SetError(dpDueDate, "Due date can not be in the past");
e.Cancel = true;
}
else
{
errorProvider1.SetError(dpDueDate, "");
}
}
我建議在驗證發票日期時調用方法Update()。
dpDueDate.Update();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.