This is a migrated thread and some comments may be shown as answers.

Bound RadMaskedEditBox MaskType = DateTime - need help setting display to null

5 Answers 126 Views
MaskedEditBox
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 2
Bronze
Iron
Veteran
Mark asked on 18 Apr 2017, 09:12 PM

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

Sort by
0
Accepted
Dimitar
Telerik team
answered on 19 Apr 2017, 09:55 AM
Hello Mark,

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
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Mark
Top achievements
Rank 2
Bronze
Iron
Veteran
answered on 19 Apr 2017, 11:43 AM

If this is documented, then I missed it.  But this is exactly what I am looking for. 

 

Thanks

0
Mark
Top achievements
Rank 2
Bronze
Iron
Veteran
answered on 19 Apr 2017, 12:51 PM
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.

 

 

0
Mark
Top achievements
Rank 2
Bronze
Iron
Veteran
answered on 19 Apr 2017, 12:54 PM
Never mind, this is working...I must have had a missed something...Anyway, thanks again for the help.
0
Dimitar
Telerik team
answered on 20 Apr 2017, 08:26 AM
Hi Mark,

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
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
MaskedEditBox
Asked by
Mark
Top achievements
Rank 2
Bronze
Iron
Veteran
Answers by
Dimitar
Telerik team
Mark
Top achievements
Rank 2
Bronze
Iron
Veteran
Share this question
or