<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Bitmatic &#187; DataGridView</title>
	<atom:link href="http://bitmatic.com/tag/datagridview/feed" rel="self" type="application/rss+xml" />
	<link>http://bitmatic.com</link>
	<description>Defragmenting a .NET programmers brain</description>
	<lastBuildDate>Tue, 13 Jul 2010 13:15:58 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Fixing a slow scrolling DataGridView</title>
		<link>http://bitmatic.com/c/fixing-a-slow-scrolling-datagridview</link>
		<comments>http://bitmatic.com/c/fixing-a-slow-scrolling-datagridview#comments</comments>
		<pubDate>Sun, 25 Oct 2009 12:14:43 +0000</pubDate>
		<dc:creator>Jakob</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[controls]]></category>
		<category><![CDATA[DataGridView]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[Scroll]]></category>
		<category><![CDATA[VS2008]]></category>

		<guid isPermaLink="false">http://bitmatic.com/?p=476</guid>
		<description><![CDATA[Whenever your C#/.NET DataGridView reaches a certain size, it tends to get really slow to scroll. Depending on the speed of your computer this may be more or less noticeable. In an application i did for a client this became a real problem due to a combination of lots of DataGridView cells and fairly slow [...]]]></description>
			<content:encoded><![CDATA[<p>Whenever your C#/.NET DataGridView reaches a certain size, it tends to get really slow to scroll. Depending on the speed of your computer this may be more or less noticeable. In an application i did for a client this became a real problem due to a combination of lots of DataGridView cells and fairly slow computers.<br />
Luckily the solution turned out to be simple&#8230;</p>
<h3>Turn on double buffering</h3>
<p>Turning on double buffering seems to solve the problem. Normally double buffering would only help reduce flickering, since painting is being done to an off-screen buffer, but for the DataGridView it also significantly reduces the amount of functions being called internally in the DataGridView &#8211; thus reducing processor load and increasing speed. (statistics gathered with the <a href="http://www.eqatec.com/tools/tracer">Eqatec Tracer</a>)</p>
<h3>My DataGridView doesn&#8217;t have a DoubleBuffered property !?!?</h3>
<p>For some reason Microsoft has decided to hide the DoubleBuffered property from DataGridView. Luckily you can set it anyway with reflection.<br />
<!-- code formatted by http://manoli.net/csharpformat/ --></p>
<pre class="csharpcode">
<span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">class</span> ExtensionMethods
{
    <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">void</span> DoubleBuffered(<span class="kwrd">this</span> DataGridView dgv, <span class="kwrd">bool</span> setting)
    {
        Type dgvType = dgv.GetType();
        PropertyInfo pi = dgvType.GetProperty(<span class="str">"DoubleBuffered"</span>,
            BindingFlags.Instance | BindingFlags.NonPublic);
        pi.SetValue(dgv, setting, <span class="kwrd">null</span>);
    }
}</pre>
<p>Just drop the above class into your project somewhere, or add the function to your existing extension methods.<br />
The extension method allows you to set the DoubleBuffered property on your DataGridView in the following manner:<br />
<!-- code formatted by http://manoli.net/csharpformat/ --></p>
<pre class="csharpcode">
dataGridView1.DoubleBuffered(<span class="kwrd">true</span>);</pre>
<p>You now have a smooth scrolling DataGridView <img src='http://bitmatic.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://bitmatic.com/c/fixing-a-slow-scrolling-datagridview/feed</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
	</channel>
</rss>
