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

TextInput EditTrigger value

1 Answer 17 Views
GridView
This is a migrated thread and some comments may be shown as answers.
J-F
Top achievements
Rank 1
J-F asked on 26 Jun 2015, 08:04 PM

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

1 Answer, 1 is accepted

Sort by
0
Ivan Ivanov
Telerik team
answered on 29 Jun 2015, 06:36 AM
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
Tags
GridView
Asked by
J-F
Top achievements
Rank 1
Answers by
Ivan Ivanov
Telerik team
Share this question
or