This documentation is archived and is not being maintained.

TextBox.SelectionLength Property

Gets or sets a value indicating the number of characters in the current selection in the TextBox.

Namespace: System.Windows.Controls
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace:

public int SelectionLength { get; set; }
/** @property */
public int get_SelectionLength ()

/** @property */
public void set_SelectionLength (int value)

public function get SelectionLength () : int

public function set SelectionLength (value : int)

<object SelectionLength="int" .../>

Property Value

An integer specifying the number of characters in the current selection in the TextBox. 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. The default value is zero (0).

Exception typeCondition


Raised if the specified selection length is negative.

In general, when a specified selection length causes the selection to end in an invalid position (i.e. between a carriage return and a new-line character, in a tag, etc), the selection length automatically adjusts so that the resulting selection starts and ends in valid positions.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0