Solved

is there any way to set the cursor in a textbox after setting the .Text property?

Posted on 2008-10-07
3
186 Views
Last Modified: 2010-04-23
I have a textbox control which I use the TextChanged event to filter out certain keypresses which I don't want to show by taking the text as a string with each keypress and filtering out any unwanted chars. The problem is that when I insert the string back into the textbox, the cursor is always at the end of the current string. Is there anyway to remember the cursor position so the user can edit the string? On second thought, I may have to rethink my whole approach.

Dan
0
Comment
Question by:zliminator
  • 2
3 Comments
 
LVL 25

Accepted Solution

by:
Luis Pérez earned 250 total points
ID: 22660391
Cursor position can be readed and writed using SelectionStart property. Try it.
0
 

Author Comment

by:zliminator
ID: 22661026
I found a SelectionStart property for the ComboBox but not for the TextBox. I'm using .Net 2.0. Is this new to 3.x? I tried it like this:
Private Sub DisplayTextBox_TextChanged(ByVal sender As System.Object, ByVal e As    System.EventArgs) Handles DisplayTextBox.TextChanged
        Dim x As Integer = DisplayTextBox.SelectionStart
but it allway gives 0

Dan
0
 

Author Comment

by:zliminator
ID: 22661083
OK, I can set it but I can't get it. All I need to do, really, is set it. I'm happy.

Dan
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

911 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now