Strange MaskedEditBox drag-and-drop behavior

4 posts, 0 answers
  1. Josh Anderson
    Josh Anderson avatar
    83 posts
    Member since:
    Dec 2005

    Posted 02 May 2008 Link to this post

    I have a MaskedEditBox set up to allow drag-and-drop, and I've encountered what I must believe is a bug of some sort.

    The control is set up with a mask for a standard North American phone number -- (###) ###-#### -- and during the DragEnter event I compare the drag data to a regex that confirms it has a phone number in it.  In the DragDrop event, I have the following code:

            private void txtConnectToPhone_DragDrop(object sender, DragEventArgs e) 
            { 
                Match dropPhone = phoneRegex.Match(e.Data.GetData(typeof(string)).ToString()); 
                if (dropPhone.Success) 
                    txtConnectToPhone.Value = dropPhone.Value.RemoveNonNumeric();    
            } 

    You can ignore the "RemoveNonNumeric()" method -- that's an extension method I have created for the string class.

    It works fine unless I have a subset of the control's text selected or the cursor positioned somewhere in the middle of the text.  For example, let's assume the control displays "(800) 555-1212" and I select the "555" portion of the string or position the cursor in front of the first 5.  If I were to drag text containing "8135551212" into the control, it would display "(800) 813-5551" indicating that it's inserting the dragged text at the point of the selection.

    The only way to get this behavior not to happen is to set the value to "" prior to setting it to the new number.  I can't imagine why this behavior would be by design.

    Josh
  2. Boyko Markov
    Admin
    Boyko Markov avatar
    610 posts

    Posted 05 May 2008 Link to this post

    Hello Josh Anderson,

    Could you try to insert the text from the index, where the maskbox's caret position is. Could you please expain in a bit more details what is the expected behavior?

    Another workaround is to modify the value of the SelectionStart property, which will change the position of the caret.

    I'm looking forward to your reply.

    Best wishes,
    Boyko Markov
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Josh Anderson
    Josh Anderson avatar
    83 posts
    Member since:
    Dec 2005

    Posted 05 May 2008 Link to this post

    Actually, the problem isn't that I'm trying to insert text, it's that I'm trying to replace the entire string.  I would expect if I set the Value property to another string altogether it would not somehow insert the text somewhere.

    Just to reiterate, my code is doing a straight assignment to the Value property, like so:

    MaskedEditBox1.Value = "8885551212"

    I would not expect this to insert text into the existing value, but rather to replace it.

    Josh
  5. Boyko Markov
    Admin
    Boyko Markov avatar
    610 posts

    Posted 07 May 2008 Link to this post

    Hi Josh Anderson,

    Your expectation is correct. I also expect when I set the Value property of the mask box to change the entire value to the new one. I will address this in the Q2 2008 release for RadControls for WinForms due in July.

    I can suggest modifying the SelectionStart property of the textBox before setting the value and initialize it to 0.

    Please write me back if you have any other questions. 

    Best wishes,
    Boyko Markov
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Back to Top