Edit this page

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. This is the default value for the SelectionOnFocus property.

  • Default - when a RadMaskedInput control is focused, the SelectionOnFocus behavior depends on the type of the control. In the RadMaskedDateTimeInput and RadMaskedTextInput the Default SelectionOnFocus behavior won't change the position of the curser (the Unchanged SelectionOnFocus behavior is applied). In the RadMaskedNumericInput and the RadMaskedCurrencyInput controls the Default SelectionOnFocus behavior will place the curser before the decimal point.

  • DefaultSelectAll - this property changes the SelectionOnFocus behavior of the control depending on the source of the focus. If a MaskedInputControl is focused on mouse click, the Default SelectionOnFocus behavior will be used. If, on the other hand, a MaskedInputControl is focused using the Tab key, the SelectAll 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

See Also

Was this article helpful? Yes No

Give article feedback

Tell us how we can improve this article

Dummy