I am playing with a Silverlight control that has a TextBox and Button. When I click the button (which calls SelectText below), I want to select all the text in the textbox.
Here’s my code:
private void SelectText() { TextBox tb = this.txtFirstName; tb.SelectionStart = 0; tb.SelectionLength = 3; // tb.Select(0, this.txtFirstName.Text.Trim().Length - 1); // tb.SelectAll(); // tb.Text = String.Empty; }
The commented code is what I tried already, but neither is working.
Anyone have suggestions on what I’m doing wrong?
You might need to give focus to the textbox to see the actual selection happening (either before or after selecting, it might not matter but you’ll have to try):