I Have a control inheriting the dataGridView control. I have the onLostFocus method overrided. Lately I encountereda weird behavior. if trying to close the form while a cell is in teh middle of being edited. the dispose method will be called and then teh onLostFocus is called that results in a nullReferenceException
protected override void OnLostFocus(EventArgs e)
{
base.OnLostFocus(e);
base.DefaultCellStyle = myStyle1;
}
}
my question is how come the lostFocus is called after the userControl starts being disposed? and what is the correct way to handle this isuue? A workaround can be to check explicitly if dispose had started and then return from the OnLostFocus. But I'd rather understans better what happens behind. Thanks!