I have a RadMaskedEditBox with the MaskType set to "DateTime", the Mask set to "MM/dd/yyyy", TextMaskFormat set to "includeLiterals". This control is programmatically bound to an object in which the Date/Time value can be null. in the KeyDown event of the control, if the user presses the "DELETE" key and the selected text is the same as the text value and the selected text length is > 0, I clear the textbox using the "CLEAR()" method and then set the value to null.
However, the display value now changes to "01/01/0001".
What am I missing.
Here is my "KeyDown" event
private void radMaskedEditBoxDate_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.Delete)
{
RadMaskedEditBox radMaskedEditBox = (RadMaskedEditBox) sender;
if (radMaskedEditBox.SelectionLength > 0 && radMaskedEditBox.SelectedText == radMaskedEditBox.Text)
{
radMaskedEditBox.Clear();
//radMaskedEditBox.Value = null;
radMaskedEditBox.Value = radMaskedEditBox.NullText;
}
}
}
5 Answers, 1 is accepted
Please note that this is supported out of the box in the latest version of the suite. The following article shows how you can enable it: Null Values Support.
With your approach you need to set the SuppressKeyPress and Handled properties:
private
void
RadMaskedEditBox1_KeyDown(
object
sender, KeyEventArgs e)
{
if
(e.KeyData == Keys.Delete)
{
RadMaskedEditBox radMaskedEditBox = (RadMaskedEditBox)sender;
if
(radMaskedEditBox.SelectionLength > 0 && radMaskedEditBox.SelectedText == radMaskedEditBox.Text)
{
radMaskedEditBox1.Value =
null
;
e.Handled =
true
;
e.SuppressKeyPress =
true
;
}
}
}
I hope this will be useful. Let me know if you have additional questions.
Regards,
Dimitar
Telerik by Progress
.jpg)
If this is documented, then I missed it. But this is exactly what I am looking for.
Thanks
.jpg)
private void radMaskedEditBox_Enter(object sender, EventArgs e)
{
RadMaskedEditBox radMaskedEditBox = (RadMaskedEditBox) sender;
radMaskedEditBox.SelectionStart = 0;
radMaskedEditBox.SelectionLength = Text.Length;
}
I do have one more question, related to this control as a DateTime. I am trying to select the entire content of the control on ENTER, but it only ever selects the first part of the date. This is my "ENTER" event.
.jpg)
I am glad that this is working fine now. Do not hesitate to contact us if you have other questions.
Regards,
Dimitar
Telerik by Progress