Unplanned
Last Updated: 28 Jul 2026 07:07 by Johannes
Johannes
Created on: 28 Jul 2026 07:07
Category: MaskedTextBox
Type: Bug Report
1
MaskedTextBox caret jumps on key press in Grid EditorTemplate

The MaskedTextBox caret (cursor) jumps to the last position on focus and every key stroke when the component is inside a Grid EditorTemplate and the Grid EditMode is InCell.

A possible workaround is to use inline or popup editing.

Test Page:

<TelerikGrid Data="@GridData"
             EditMode="@GridEditMode.Incell"
             OnUpdate="@OnGridUpdate"
             OnCreate="@OnGridCreate">
    <GridToolBarTemplate>
        <GridCommandButton Command="Add">Add Item</GridCommandButton>
    </GridToolBarTemplate>
    <GridColumns>
        <GridColumn Field="@nameof(Product.Name)" />
        <GridColumn Field="@nameof(Product.MaskedValue)">
            <EditorTemplate>
                @{ var dataItem = (Product)context; }
                <TelerikMaskedTextBox @bind-Value="@dataItem.MaskedValue"
                                      Mask="AAA-AAA" />
            </EditorTemplate>
        </GridColumn>
    </GridColumns>
</TelerikGrid>

@code {
    private List<Product> GridData { get; set; } = new();

    private int LastId { get; set; }

    private void OnGridCreate(GridCommandEventArgs args)
    {
        var createdItem = (Product)args.Item;

        createdItem.Id = ++LastId;

        GridData.Insert(0, createdItem);
    }

    private void OnGridUpdate(GridCommandEventArgs args)
    {
        var updatedItem = (Product)args.Item;
        var originalItemIndex = GridData.FindIndex(i => i.Id == updatedItem.Id);

        if (originalItemIndex != -1)
        {
            GridData[originalItemIndex] = updatedItem;
        }
    }

    protected override void OnInitialized()
    {
        for (int i = 1; i <= 5; i++)
        {
            GridData.Add(new Product()
            {
                Id = ++LastId,
                Name = $"Product {LastId}",
                MaskedValue = $"ABC-{LastId:D3}"
            });
        }
    }

    public class Product
    {
        public int Id { get; set; }
        public string Name { get; set; } = string.Empty;
        public string MaskedValue { get; set; } = string.Empty;
    }
}

0 comments