Caret Position SelectionStart, Simple?
This should be simple...
I have a maskedtextbox on a form, and I've added an OnEnter event which I want to set the caret position to zero (it defaults to the end). From what I've read you should use the SelectionStart Property to do this, but I can't get it to work. In the debugger it seems to reflect the correct selectionStart position but even though I set the value the caret doesn't get repositioned. I've also tried setting the selection length to various numbers along with the selectionStart...
Any help would be greatly appreciated.
[571 byte] By [
Blast] at [2007-12-25]
I've gotta be doing something wrong. This is driving me crazy!
This didn't work, I stepped through the debugger to make sure the event is being fired but sure enough it fires correctly but the position isn't set. Again, I just have an onEnter event on the control, which has maskedTextBox.select(0,0); I am tabbing over to the control to fire the event... I am doing something wrong?
private void maskedTextBox1_Enter(object sender, EventArgs e){
this.maskedTextBox1.Select(0,0); }
Here is my code... The control IS being hosted by a usercontrol...if that matters. After this event fires the caret is still positioned at the end. I am using a mask...I'm not sure if that matters.
Help!
Hmmm. Ok, yeah I'll do that. Sounds to me like it should work. Have you tried hosting the maskedtextbox in a usercontrol? Maybe thats the problem. I will test out both myself tomorrow morning and repost. Thanks for your response!
Problem seems to be when you add a mask. If there is no mask, the caret gets put back to 0, if there is a mask, then the caret stays at the end. Anyone know how to work around this?
True, I didnot add any mask and did not test it with Mask, I'll check it when I have timie tomorrow.
I wish your problem is solved soon.
Best Regards,
Ahh, I'll remember this. But this is seemed some type of bug observe the meaning of two things Select(0,0); and SelectionStart = 0, The other thing BeginInvoke has some different purpose.
Anyhow, your problem is solved! i'm happy for that!