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]
# 1

Try this:

maskedTextBox.Select(0,0);

Cheers ;-)

RizwanSharp at 2007-8-31 > top of Msdn Tech,Visual C#,Visual C# General...
# 2

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!

Blast at 2007-8-31 > top of Msdn Tech,Visual C#,Visual C# General...
# 3

I must test it, Please hold on for 5-10 minutes I check it,

cya

RizwanSharp at 2007-8-31 > top of Msdn Tech,Visual C#,Visual C# General...
# 4

It works fine with me....... I dont know why its not workign for you. Try it in a seperate application, Use TextBox on Form and then on UserControl see behaviors.

I hope this will work!!!

Cheers ;-)

RizwanSharp at 2007-8-31 > top of Msdn Tech,Visual C#,Visual C# General...
# 5

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!

Blast at 2007-8-31 > top of Msdn Tech,Visual C#,Visual C# General...
# 6

No I've not tried in UserControl and left this job on you coz didnot have much time. And tell me what are the results.

Best Regards,

RizwanSharp at 2007-8-31 > top of Msdn Tech,Visual C#,Visual C# General...
# 7

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?

Blast at 2007-8-31 > top of Msdn Tech,Visual C#,Visual C# General...
# 8

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=194478&SiteID=1

I think this is what I am looking for.

Blast at 2007-8-31 > top of Msdn Tech,Visual C#,Visual C# General...
# 9

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,

RizwanSharp at 2007-8-31 > top of Msdn Tech,Visual C#,Visual C# General...
# 10

Thanks for your time RizwanSharp, apparently you can use the beginInvoke method to set the StartSelection when you have a mask.

Blast at 2007-8-31 > top of Msdn Tech,Visual C#,Visual C# General...
# 11

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!

RizwanSharp at 2007-8-31 > top of Msdn Tech,Visual C#,Visual C# General...