Posted 17 October 2023, 8:45 pm EST
Hi C1,
see attached sample:
C1DateEditEnter.zip
I have a C1DateEdit on a modal dialog.
When pressing “Escape” while C1DateEdit is focused, I would expect the dialog to close with DialogResult = “Cancel”.
When pressing “Enter”, the same should happen with Dialog = “OK”.
C1DateEdit has a property “AcceptsEscape”, but it does not seem to work.
And a property “AcceptsEnter” is missing.
I tried to achieve this by handling “C1DateEdit.KeyPress”. But this does not work very well, because:
a) when pressing “Escape” while having typed a partial date part (e.g. “19” in the year field), I would expect it to cancel the editing process and stay in the dialog. The second “Escape” then should close the dialog.
b) same for “Enter” with a partial input: the “Value” of C1DateEdit is not updated properly, and thus “C1DateEdit.Value” still returns the date before starting editing.
The ENTER issue could be worked around by calling “UpdateValueWithCurrentText”. But for the “Escape” issue I have no workaround - there is no property to detect that C1DateEdit is still in edit mode:
Here is a possible code to apply those keys:
private void c1DateEdit1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == 13)
{
//ENTER:
if (this.c1DateEdit1.UpdateValueWithCurrentText() == false)
{
MessageBox.Show(this, "ENTER canceled - could not update text to value: " + this.c1DateEdit1.Value);
this.buttonOK.PerformClick();
}
else
{
MessageBox.Show(this, "ENTER: " + this.c1DateEdit1.Value);
this.buttonOK.PerformClick();
}
}
else if (e.KeyChar == 27)
{
//ESCAPE:
//TODO: first "Escape" should cancel an unfinished editing...
MessageBox.Show(this, "ESCAPE: " + this.c1DateEdit1.Value);
this.buttonCancel.PerformClick();
}
}
We got a user bugreport that in small “Go to date” dialog of ours ENTER does not close the dialog. This brought me to this issue.
Would be great if you could add a property “AcceptsEnter” to C1DateEdit. And the bonus would be to fix “AcceptsEscape” ;-).
Best regards
Wolfgang