This is a migrated thread and some comments may be shown as answers.

RadMaskedNumericInput: Position of caret on focus

1 Answer 138 Views
MaskedInput (Numeric, DateTime, Text, Currency)
This is a migrated thread and some comments may be shown as answers.
Fabrice
Top achievements
Rank 1
Fabrice asked on 29 Feb 2016, 12:18 PM

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?

 

 

1 Answer, 1 is accepted

Sort by
0
Accepted
Dinko | Tech Support Engineer
Telerik team
answered on 03 Mar 2016, 11:40 AM
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.

Regards,
Dinko
Telerik
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
Tags
MaskedInput (Numeric, DateTime, Text, Currency)
Asked by
Fabrice
Top achievements
Rank 1
Answers by
Dinko | Tech Support Engineer
Telerik team
Share this question
or