How can I use DataGridView's CellEnter and CellLeave events?
I need to handle some things during a cell enter and a cell leave. However, I'm finding that these are fired at times where the cell is not physically being entered (tabbed into or mouse-clicked). For instance, they seem to be getting fired when I chan开发者_开发技巧ge the data source. I've overridden the OnDataSourceChanged event in such a way:
protected override void OnDataSourceChanged(EventArgs e)
{
_isBinding = true;
base.OnDataSoruceChanged(e);
_isBinding = false;
}
Then, I use the _isBinding flag in the CellEnter event to bypass my logic. However, then I saw that the OnBindingContextChanged event was also triggering these event. I could override this event also, but when does it end? There could be other events that call the CellEnter/CellLeave events that I haven't tested. Is there a better way?
精彩评论