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

6 posts, 1 answers
  1. Mark
    Mark avatar
    66 posts
    Member since:
    Oct 2014

    Posted 18 Apr Link to this post

    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;
          }
       }
    }

  2. Answer
    Dimitar
    Admin
    Dimitar avatar
    1871 posts

    Posted 19 Apr Link to this post

    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.
  3. Mark
    Mark avatar
    66 posts
    Member since:
    Oct 2014

    Posted 19 Apr in reply to Dimitar Link to this post

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

     

    Thanks

  4. Mark
    Mark avatar
    66 posts
    Member since:
    Oct 2014

    Posted 19 Apr in reply to Mark Link to this post

    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.

     

     

  5. Mark
    Mark avatar
    66 posts
    Member since:
    Oct 2014

    Posted 19 Apr in reply to Mark Link to this post

    Never mind, this is working...I must have had a missed something...Anyway, thanks again for the help.
  6. Dimitar
    Admin
    Dimitar avatar
    1871 posts

    Posted 20 Apr Link to this post

    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.
Back to Top