RadMaskedNumericInput: Position of caret on focus

2 posts, 1 answers
  1. Fabrice
    Fabrice avatar
    22 posts
    Member since:
    Jan 2015

    Posted 29 Feb 2016 Link to this post

    I have a question regarding a GridViewMaskedInputColumn with a MaskType = MaskType.Numeric with a short width, so I'll place this question under this forum.


    When I focus on the cell the caret seems to be placed at the beginning of the content, and (a) happens (see attached file). I wanted to achieve something like (b).


    I inherited GridViewMaskedInputColumn and if I do:


    public class SomeGridViewMaskedInputColumn : GridViewMaskedInputColumn
            public override FrameworkElement CreateCellEditElement(GridViewCell cell, object dataItem)
                var elem = (RadMaskedNumericInput)base.CreateCellEditElement(cell, dataItem);
                elem.GotFocus += Elem_GotFocus;

                // I tried SetCaretToEndOfTextOnFocus(elem, true); but it doesnt work for some reason
                return elem;

            private void Elem_GotFocus(object sender, RoutedEventArgs e)
                var control = ((RadMaskedNumericInput)sender);
                control.SelectionStart = control.Text.IndexOf(",");


    (c) happens. In fact, (b) looks only achievable if i set SelectionStart to control.Text.Length and then press left 2 times (in this case, because i have 2 decimal places). Is there a better way of doing this?



  2. Answer
    Dinko avatar
    442 posts

    Posted 03 Mar 2016 Link to this post

    Hi Fabrice,

    The approach that you have implemented in your application is suitable. Another one that you can try is to subscribe to the PreparedCellForEdit event of the RadGridView. Then you can set the start position of the caret when you focus the RadMaskedNumericInput control. You can check the code snippet below:
    <telerik:RadGridView PreparedCellForEdit="Grid_PreparedCellForEdit" />
    private void Grid_PreparedCellForEdit(object sender, GridViewPreparingCellForEditEventArgs e)
        RadMaskedNumericInput input = e.EditingElement as RadMaskedNumericInput;
        input.SelectionStart = input.Text.IndexOf(".");

    Hope this information is helpful.

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top