Posted 11 July 2023, 4:35 pm EST - Updated 11 July 2023, 4:43 pm EST
This is a followup to https://www.grapecity.com/forums/winforms-edition/net6-problems-in-c1dateedit-customformat-postvalidation: I found three problems in C1DateEdit validation.
All issues happen with a custom german format (“dd.MM.yyyy”). I know that this could be replaced by standard format “ShortDate”, but it is just a sample format - in our app we use “ddd dd.MM.yyyy”.
C1DateEditValidation603.zip
Problem 1: when entering a partial day value (“1”, “2” or “3”) and pressing “TAB”, the control contains the valid DateTime (the input is handled as “01”, “02” or “03”), but the control still renders “1”, “2”, “3”.
Problem 2: due to historical reasons, in our C1DateEdit subclass I override “OnValueChanged” and call “C1DateEdit.ParseContent” again. And here, “ParseContent” fails. Maybe this is also the reason why the date is not rendered properly?
This is shown in the sample: remove the “return” statement in “c1DateEdit2_ValueChanged” so that this code is activated:
object objhelp;
ErrorInfo errInfo = this.c1DateEdit2.ErrorInfo;
ErrorReason errReason = this.c1DateEdit2.ParseContent(out objhelp, errInfo);
if (errReason != ErrorReason.None)
{
MessageBox.Show(this, "Validation failed (Current Value: " + this.c1DateEdit2.Value + "): Error = " + errInfo.ErrorMessage);
}
else
{
MessageBox.Show(this, "Validation is OK (Current Value: " + this.c1DateEdit2.Value + ")");
}
My workaround is to remove the “ParseContent” call in “OnValueChanged” and hope that the current input is always valid. Maybe I did this because we use a timer to trigger “ValueChanged” after typing text and waiting a second.
Problem 3: it seems “PostValidation” intervals using DateTime values still do not work. In the previous forum thread, I wrote that it works, and in our “real” application it seems to do so. But in my sample, it fails: uncomment line 18:
this.c1DateEdit2.PostValidation.Intervals.Add(new ValueInterval(new DateTime(2023, 1, 1), new DateTime(2013, 12, 31), true, true));
Now you cannot enter any date in the picker.
It works with string value intervals:
this.c1DateEdit2.PostValidation.Intervals.Add(new ValueInterval("2023-01-01", "2023-12-31", true, true));
Of course, those issues were found only after releasing our app version containing C1DateEdit .603 :-(.
Best regards
Wolfgang