I'm using a DataGridView with C#.NET. When a user is editing a column, I need another column in the same grid to change with every keystroke/change. How/where do I insert my own code for this type of event?
views:
82answers:
1What you're trying to achieve is not possible without a bit of work. By default the DataGridView
class does not provide a CellChanging
style event. Instead it provides book ended events in the form of CellBeginEdit
and CellEndEdit
.
Part of the reason is likely due to the varying ways in which a cell can be editted. Having a CellChanging
would make sense for a text style cell but wouldn't make as much sense for say a Button
style cell.
You could easily implement a solution though which propagated the value once it was completely entered via the above said events.
The only way I can see to implement it for every keystroke would be to
- Handle the above events
- Figure out what the runtime type of
DataGridView.EditingControl
is and find a way to hook into every single change for every type of cell - Propagate the changes on every edit
Even then I think you still may run into issues because I'm not sure if DataGridView
is designed to have cell values changed while a different one is being actively edited.