I have a DataGridView (WinForms) in which I have defined a custom EditingControl derived from DataGridViewTextBoxEditingControl that only allows numeric characters.
I need to raise CellValueChanged event on the DataGridView each time the user press a key, but the default behaviour is to raise the event only when edition has been completed.
How can I raise the event each time a key is pressed?
public class DataGridViewNumericTextBoxEditingControl : DataGridViewTextBoxEditingControl
{
protected override void OnKeyPress(KeyPressEventArgs e)
{
e.Handled = Char.IsLetter(e.KeyChar);
if (!e.Handled)
RaiseDataGridViewCellValueChanged(); // <-- Any way?
}
}
Update:
I've found a workaround, but I'm not sure it's a good solution:
public class DataGridViewNumericTextBoxEditingControl : DataGridViewTextBoxEditingControl
{
protected override void OnKeyPress(KeyPressEventArgs e)
{
e.Handled = Char.IsLetter(e.KeyChar);
if (!e.Handled)
{
EditingControlDataGridView.EndEdit();
EditingControlDataGridView.BeginEdit(false);
}
}
}