This topic has not yet been rated - Rate this topic

TextBox.SelectionLength Property

April 12, 2014

Gets or sets the number of characters in the current selection in the text box.

Namespace:  System.Windows.Controls
Assembly:  System.Windows (in System.Windows.dll)
XMLNS for XAML: Not mapped to an xmlns.
'Declaration
Public Property SelectionLength As Integer
<TextBox SelectionLength="int"/>

Property Value

Type: System.Int32
The number of characters in the current selection in the text box, or 0 if there is no selection.
ExceptionCondition
ArgumentOutOfRangeException

The value is less than 0.

Getting this property returns the number of characters in the current selection. Setting this property adjusts the length of the current selection to the specified value, keeping the beginning of the selection fixed.

If the specified selection length is longer than the amount of text, the selection length automatically adjusts so that the resulting selection is never more than the amount of text.

A SelectionChanged event is raised when a valid SelectionLength is set.

The following code example shows how you can use the SelectionLength property.


Private Sub SelectionLength()

    'The first five characters in MyTB1 are selected. 
    MyTB1.SelectionLength = 5
End Sub


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.