Databound RadMaskedEditBox caret position issue

3 posts, 1 answers
  1. Larry
    Larry avatar
    6 posts
    Member since:
    Nov 2014

    Posted 11 Sep Link to this post

    I have a RadMaskedEdit box for phone number entry.

    ...
        Telerik.WinControls.UI.RadMaskedEditBox editPhone = new Telerik.WinControls.UI.RadMaskedEditBox();
    ...
        editPhone.Mask = "(000)000-0000";
        editPhone.MaskType = Telerik.WinControls.UI.MaskType.Standard;
        editPhone.Name = "editPhone";
        editPhone.Text = "(___)___-____";
        editPhone.TextMaskFormat = System.Windows.Forms.MaskFormat.IncludeLiterals;

     

    I have defined a Customer class (simplified for this example)

    public class Customer {
      public string CustomerName { get; set; }
      public string PhoneNumber { get; set; }
    }

     

    I bind the RadMaskedEditBox Value property to the PhoneNumber property of a Customer object.

      Customer editCustomer = new Customer();
    ...
      editPhone.DataBindings.Clear();
      editPhone.DataBindings.Add("Value", editCustomer, "PhoneNumber", false, DataSourceUpdateMode.OnPropertyChanged | DataSourceUpdateMode.OnValidation);

     

    After this, when editing the phone number, using the "Del" or "Backspace" key will properly remove the character, but will move the caret to the first position of the text box.

    If I remove the Data Binding, the "Del" and "Backspace" keys work as expected.  I don't have any event handling code for this control.  Currently we are using version 2016.3.913.40.

    Is there a workaround, fix, or other change I can implement that will avoid the behavior as I've described?

     

  2. Answer
    Dimitar
    Admin
    Dimitar avatar
    1877 posts

    Posted 12 Sep Link to this post

    Hi Larry,

    Just enable the formatting of the binding:
    editPhone.DataBindings.Add("Value", editCustomer, "PhoneNumber", true, DataSourceUpdateMode.OnPropertyChanged | DataSourceUpdateMode.OnValidation);

    I hope this will be useful. 

    Regards,
    Dimitar
    Progress Telerik
    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. Larry
    Larry avatar
    6 posts
    Member since:
    Nov 2014

    Posted 12 Sep in reply to Dimitar Link to this post

    Dimitar - That did the trick.  

    Thank you.

Back to Top