Solved

Formatting a Textbox

Posted on 2006-10-27
3
201 Views
Last Modified: 2010-04-23
Hi all,

I have a textbox on my form and I would like the user to enter 4 numbers into it and have the textbox automatically format it to xx/xx as they are typing. I have tried using the below code but when I do once the first two numbers have been typed the cursor is moved back to the start of the box rather than after the "/"

If txtboxExp.Text.Length = 2 Then
       txtboxExp.Text = txtboxExp.Text & "/"
End If

Can someone let me know and easy way of creating a custom format for a textbox like this.
Thanks
0
Comment
Question by:kiranboi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 17

Accepted Solution

by:
ZeonFlash earned 500 total points
ID: 17818888
Try this:

            If txtboxExp.Text.Length = 2 Then
                  txtboxExp.Text = txtboxExp.Text & "/"
                  txtboxExp.SelectionStart = txtboxExp.Text.Length
            End If
0
 

Author Comment

by:kiranboi
ID: 17818927
Perfect.

Thanx
0
 
LVL 5

Expert Comment

by:xersoft
ID: 17818938
If you are using .net 2.0 you can use the masked edit textbox and set the mask to "00/00" Does that provide what you are after?
0

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question