Results 1 to 5 of 5

Thread: [RESOLVED] Masked textbox displays numbers in reverse order

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2012
    Location
    Caracas, Venezuela
    Posts
    121

    Resolved [RESOLVED] Masked textbox displays numbers in reverse order

    Hello friends:

    I have a masked textbox on a form, masked to handle phone numbers and requiring all numbers, I mean000)000-0000

    I found an issue with it, since it receives the numbers where the user clicks. Therefore I used the SelectionStart property under a keydown event. The code is below.

    It takes the cursor to the beguinning, but the numbers are entered or received in reverse order. I mean, the number (754)963-9183 is entered or received as (381)936-9457.

    HTML Code:
    Private Sub TelefonoMKTxt_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TelefonoMKTxt.KeyDown
            TelefonoMKTxt.SelectionStart = 0
        End Sub
    Any help will be appreciated.


    Nelson

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,711

    Re: Masked textbox displays numbers in reverse order

    Anytime that you type in TelefonoMKTxt it will send the caret to the start, this is why it is prepending values instead of appending them. Why are you setting the SelectionStart in the first place?
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2012
    Location
    Caracas, Venezuela
    Posts
    121

    Re: Masked textbox displays numbers in reverse order

    Hello dday9,

    Thanks for the response.

    your answer is quite logical.

    I used SelectionStart because when I enter the masked textbox the cursor starts where I clicked. Therefore, the numbers I am tipying enter at that point. Since the point usually is not the start one of the masked textbox, the end of the mask is reached, but the complte phone nunber has not been entered. I just suposed that by getting the very beguinning of the masked textbox, the necesary places for all of the digits were going to be granted.

    If you know a way to solved this issue, it will be welcome.

    Thank you againg.

    Nelson

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: Masked textbox displays numbers in reverse order

    Using SelectionStart is ok to set the position... but doing it in the KeyDown event is an odd choice, because then it happens every time a key is pressed.

    It would make more sense to use an event related to receiving the focus (such as GotFocus), or a mouse related event (such as MouseDown).


    It may also make sense to set the position to just after the last character entered, rather than at the start (for situations where the user starts typing the number, but pops back to something else before finishing).

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Oct 2012
    Location
    Caracas, Venezuela
    Posts
    121

    Re: Masked textbox displays numbers in reverse order

    Thank you si_the_geek.

    With Mousedown It works great.

    Thanks to dday9 too.

    Nelson

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width