Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Controls / August 2007

Tip: Looking for answers? Try searching our database.

MaskedTextBox.SelectionStart Not working

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jason Allred - 28 Aug 2007 18:26 GMT
I have six .NET 2.0 MaskedTextBoxes in a user control (With a mask on each
of 3 numeric characters).  When the length of the text in the right-most
masked textbox is 0, I want to put the cursor at the end of the previous
(5th) masked textbox.  I've tried the following:

       Private Sub mtb6_TextChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles mtb6.TextChanged
           Select Case Me.mtb6.Text.Length
               Case Me.intMaxEntryLength
                   Exit Select
               Case 0
                   Me.mtb5.SelectionStart = Me.mtb5.Text.Length
                   Me.mtb5.Focus()
               Case Else
                   Exit Select
           End Select
       End Sub

All I ever get, regardless of where I set the SelectionStart property, is
the cursor showing up between the 1st and 2nd character.  As I would
suspect, if I set the SelectionStart property to -1, I get an exception.
However, If I set the SelectionStart property to some absurd number (say
43465491651), I get the same results (i.e. between the 1st and 2nd
character).

Is this a problem with the control, or just my implementation of it?

Regards,

Jason.
Jason Allred - 28 Aug 2007 18:52 GMT
I found the solution in the MSDN documentation:

You can programmatically move the caret within the text box by setting the
SelectionStart to the position within the text box where you want the caret
to move to and set the SelectionLength property to a value of zero (0). The
text box must have focus in order for the caret to be moved.
So all I had to do was call the Focus() method prior to setting the
SelectionStart and SelectionLength Properties.

>I have six .NET 2.0 MaskedTextBoxes in a user control (With a mask on each
>of 3 numeric characters).  When the length of the text in the right-most
[quoted text clipped - 26 lines]
>
> Jason.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.