Working with Selection
The purpose of this tutorial is to walk you through the common task of configuring RadMaskedInput
control for working with selection. The following "selection" features will be demonstrated:
SelectionOnFocus
The SelectionOnFocus
property of the RadMaskedInput controls allows you to specify what will happen with the cursor when the control gets focus. The values for the SelectionOnFocus property are predefined in the SelectionOnFocus enumeration. It exposes the following members:
-
SelectAll
—once a RadMaskedInput control is focused, it will select its whole text.Example 1: Setting the SelectionOnFocus property to SelectAll
<telerik:RadMaskedTextInput Mask="###-###-###" SelectionOnFocus="SelectAll" />
-
CaretToBeginning
—once a RadMaskedInput control is focused, the cursor will be positioned at its beginning.Example 2: Setting the SelectionOnFocus property to CaretToBeginning
<telerik:RadMaskedTextInput Mask="###-###-###" SelectionOnFocus="CaretToBeginning" />
-
CaretToEnd
—once a RadMaskedInput control is focused, the cursor will be positioned at its end.Example 3: Setting the SelectionOnFocus property to CaretToEnd
<telerik:RadMaskedTextInput Mask="###-###-###" SelectionOnFocus="CaretToEnd" />
Unchanged
—when a RadMaskedInput control is focused, the position of the cursor won't be changed.-
Default
—When a RadMaskedInput control is focused, the SelectionOnFocus behavior depends on the type of the control. This is the default value for the SelectionOnFocus property.- In the
RadMaskedDateTimeInput
andRadMaskedTextInput
theDefault
behavior will place the cursor at the beginning if the value of the control is still not set. Otherwise the control won't change the position of the cursor - theUnchanged
behavior is applied. - In the
RadMaskedNumericInput
and theRadMaskedCurrencyInput
controls theDefault
behavior will place the cursor before the decimal point if the value of the control is still not set. Otherwise the control will behave as if in theUnchanged
mode.
- In the
DefaultSelectAll
—this property changes the SelectionOnFocus behavior of the control depending on the source of the focus. If a RadMaskedInput control is focused on mouse click, the Default behavior will be used. If, on the other hand, a RadMaskedInput is focused using the Tab key, theSelectAll
SelectionOnFocus behavior will be used.
SelectionLength and SelectionStart
The SelectionStart
property gets or sets the starting point of the selected text in the RadMaskedInput, while the SelectionLength
gets or sets the number of characters selected in the RadMaskedInput. Both of the properties could be used in a combination with the GotFocus
event, like in the example below:
Example 4: Subscribe to the GotFocus event in XAML
<telerik:RadMaskedTextInput Mask="###-###-###" x:Name="radMaskedTextInput" GotFocus="radMaskedTextInput_GotFocus"/>
Example 5: Setting the SelectionStart and SelectionLength properties
private void radMaskedTextInput_GotFocus(object sender, RoutedEventArgs e)
{
radMaskedTextInput.SelectionStart = 2;
radMaskedTextInput.SelectionLength = 2;
}
Private Sub radMaskedTextInput_GotFocus(sender As Object, e As RoutedEventArgs)
radMaskedTextInput.SelectionStart = 2
radMaskedTextInput.SelectionLength = 2
End Sub