tags:

views:

1182

answers:

1

I'm using a WPF TextBox, and I'm calling the Select() method to make a selection. Unfortunately, it doesn't seem to work unless I select something manually first. Can someone suggest as to why it happens?

+3  A: 

Does your textbox have focus when you call the Select method?

The selection will not show unless it has focus, but the common way for the textbox to get focus is by clicking on it...which deselects the text. This behaviour could give the impression that it's not working.

Calling TextBox.Focus() after (or before) calling Select() should fix it.

Bubblewrap
Why aren't those things in the Select documentation? It would keep alot of frustrations from beginners like me.
Elazar Leibovich