The reason why sometimes a grid control shows a big red X and stops working properly is because an unhandled exception has occurred during the control’s OnPaint event.
One way to handle this is by extending from the grid control and overriding the OnPaint event so that any exceptions can be handled. Of course, the best solution is to try and prevent such exceptions from happening in the first place.
public class SafeDataGridView : DataGridView { protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { try { base.OnPaint(e); } catch (Exception) { this.Invalidate(); } } }
Thank you Koen, it worked for me!
(VS2015. framework 4.6)
Regards
Could this give rise to an infinite loop?