I'm instantiating a DataGridView within a UserControl that is instantiated via Reflection and then added to a panel within my main Form. When I add the UserControl to the panel, the DataGridView CellEnter event is fired, then the CellLeave event is fired, and then the CellEnter event is fired again. There's no 2nd CellLeave event fired. The Call Stack while in the event handlers shows all of this happens as a result of the statement that adds the UserControl to the panel. Once the Form is configured and displayed for user action, the UserControl does not have focus because my code sets the focus on a different control that's elsewhere on the Form.
The documentation for the DataGridView CellEnter event indicates the event may fire twice when a cell is clicked before the control has input focus (which the debugger shows it does not while in the event handler) and the clicked cell was not previously the CurrentCell (which the debugger shows it is). This wouldn't seem to be relevant since no cell has been clicked at the point when the UserControl is added to the Form, but I thought I'd mention it anyway.
Any thoughts on why CellEnter fires twice and/or why CellLeave does not? In any case, is there any way around this? I want CellEnter to set a UI element and CellLeave to unset it. The latter isn't happening since CellEnter is the last event to fire.
Thanks. Steve
Here's the Call Stack on the 1st and 2nd CellEnter events: