TextInput EditTrigger value

2 posts, 0 answers
  1. J-F
    J-F avatar
    13 posts
    Member since:
    Dec 2010

    Posted 26 Jun 2015 Link to this post

    Hi,

    I’m trying to only allow certain character in some columns (for example no letter in a columns). I’ve manage to do this easily but getting access to the TextBox’s event in the PreparingCellForEdit event.

    My issue is that it does not cover the TextInput EditTrigger value, since it that will overwrite the previous value of the field. I’ve managed to get the value (the letter that was typed) from the EditingEventArgs property of the GridViewPreparingCellForEditEventArgs in the PreparingCellForEdit event by casting it to a TextCompositionEventArgs and then reading the Text property but by then, cancelling the event doesn’t not prevent the editor from being display.

    Is there a better solution? Ideally I would need the TextInput EditTrigger value in the BeginningEdit event.

     

    Thanks

  2. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1217 posts

    Posted 29 Jun 2015 Link to this post

    Hello,

    If I have understood your requirement correctly, I believe that there is an easier approach. You can subscribe to PreviewKeyDown and handle it for cells that do not match the condition:
    private void clubsGrid_PreviewKeyDown(object sender, KeyEventArgs e)
    {
        var cell = e.OriginalSource as GridViewCell;
     
        if (cell != null && cell.Column.DisplayIndex == 2 && e.Key == Key.A)
        {
            e.Handled = true;
        }
    }
    For example, this code prevents the input of "A" in the third column. If the raising of KeyDown is prevented, TextInput will not be raised.

    Regards,
    Ivan Ivanov
    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
Back to Top