I recently came across a problem on one of my applications which was causing a huge slow down on its performance.

Just to give you an idea, the application I’m talking about has a DataGridView that takes 80% of the screen which lists a lot of data extracted from a Database. It allows users to use a bunch of different filters to narrow down the results they see on the grid, and they can manipulate the data on it through a context menu strip.
About three weeks ago, a user mailed me saying that lately he was having a hard time using the application because every now and then the window would show blank spots as if the controls had vanished. Long story short, after digging a bit into the problem I realized the issue was directly related to the DataGridView component I had on the window. I am handling the CellFormatting event in order to change row background colors along with a bunch of other things and it is SLOW. So slow that if you have a considerable amount of formatting being done on each row, you can actually see it being painted/redrawn.

So the solution is simple, make use of Double Buffering. It basically renders all graphics to memory prior to show them, rather than rendering them directly to screen thus making the process extremely slow. Now, there is no DoubleBuffered option on the DataGridView component (it is protected) so to work this around, you either make an extension of it OR you change it via Reflection. I prefer the last option, so this is what I have made:

 BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetProperty,
 new object[] { true });

I added this piece of code to the Form_Load event and the CellFormatting performance issue was gone.