title: Horrible redraw performance of the DataGridView on one of my two screens
body: <h2>I've actually solved this, but I'm posting it for posterity.</h2>
  
  <p>I ran into a very odd issue with the DataGridView on my dual-monitor system. The issue manifests itself as an EXTREMELY slow repaint of the control (<em>like 30 seconds for a full repaint</em>), but only when it is on one of my screens. When on the other, the repaint speed is fine.</p>
  
  <p>I have an Nvidia 8800 GT with the latest non-beta drivers (175. something). Is it a driver bug? I'll leave that up in the air, since I have to live with this particular configuration. (It does not happen on ATI cards, though...)</p>
  
  <p>The paint speed has nothing to do with the cell contents, and custom drawing doesn't improve the performance at all - even when just painting a solid rectangle.</p>
  
  <p>I later find out that placing a ElementHost (from the System.Windows.Forms.Integration namespace) on the form corrects the problem. It doesn't have to be messed with; it just needs to be a child of the form the DataGridView is also on. It can be resized to (0, 0)  as long as the <em>Visible</em> property is true.</p>
  
  <p>I don't want to explicitly add the .NET 3/3.5 dependency to my application; I make a method to create this control at runtime (if it can) using reflection. It works, and at least it fails gracefully on machines that don't have the required library - it just goes back to being slow.</p>
  
  <p>This method also lets me apply to fix while the app is running, making it easier to see what the WPF libraries are changing on my form (using Spy++).</p>
  
  <p>After a lot of trial and error, I notice that enabling double buffering on the control itself (as opposed to just the form) corrects the issue!</p>
  
  <hr>
  
  <p>So, you just need to make a custom class based off of DataGridView so you can enable its DoubleBuffering. That's it!</p>
  
  <pre><code>class CustomDataGridView: DataGridView
  {
      public CustomDataGridView()
      {
          DoubleBuffered = true;
      }
  }
  </code></pre>
  
  <p>As long as all of my instances of the grid are using this custom version, all is well. If I ever run into a situation caused by this where I'm not able to use the subclass solution (if I don't have the code), I suppose I could try to inject that control onto the form :) (<em>although I'll be more likely to try using reflection to force the DoubleBuffered property on from the outside to once again avoid the dependency</em>).</p>
  
  <p>It is sad that such a trivially simple thing ate up so much of my time...</p>