So here’s the scenario – you’ve got some kind of code that you want to run whenever the value of a cell changes in a DataGridView. You write some code in the DataGridView’s
CellValueChanged event, but you notice that it doesn’t fire if you are editing a cell and then you close the form without first tabbing/clicking out of the DataGridView (I noticed this when working on my IsDirty class, described in my last post).
There is a very quick and dirty solution to this problem – in the
FormClosing event, set focus on another form element, like a textbox (for example,
txtFirstName.Focus()). This will cause the focus to leave the DataGridView, which will cause the
CellValueChanged event to fire, which will cause your
CellValueChanged code to run.