<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:series="http://unfoldingneurons.com/" version="2.0">

<channel>
	<title>Anuj Varma</title>
	
	<link>http://www.anujvarma.com</link>
	<description>Web Log of a techie, globetrotter, uber geek</description>
	<lastBuildDate>Sun, 19 Feb 2012 21:06:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/AnujVarmaWeb" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="anujvarmaweb" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>A probability problem – will these two friends ever meet?</title>
		<link>http://www.anujvarma.com/a-probability-problem-will-these-two-friends-ever-meet/</link>
		<comments>http://www.anujvarma.com/a-probability-problem-will-these-two-friends-ever-meet/#comments</comments>
		<pubDate>Fri, 23 Dec 2011 13:30:45 +0000</pubDate>
		<dc:creator>Anuj Varma</dc:creator>
				<category><![CDATA[Probability]]></category>

		<guid isPermaLink="false">http://www.anujvarma.com/a-probability-problem-will-these-two-friends-ever-meet/</guid>
		<description><![CDATA[
Two friends decide to meet at a definite place between 9 AM and 10 AM. The first to arrive waits for his friend for 15 minutes and then leaves. If each of them arrives at an arbitrary moment between 9 &#8230; <a href="http://www.anujvarma.com/a-probability-problem-will-these-two-friends-ever-meet/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[</p>
<p>Two friends decide to meet at a definite place between 9 AM and 10 AM. The first to arrive waits for his friend for 15 minutes and then leaves. If each of them arrives at an arbitrary moment between 9 and 10 AM, find the probability that they will meet.</p>
<h3>First Step – Sample Space</h3>
<p>We can treat this problem geometrically. The interval from 9:00 AM to 10:00 AM represents a segment of length 1. Let a unit length segment on the x axis represent one friend’s sample space. Let a unit segment on the y axis represent the other friend’s sample space. The total sample space is then an area of unit length squared. Every point in this unit square represents the arrivals of the two friends. </p>
<h3>Geometric Interpretation of the condition</h3>
<p>The events(x,y) during which the friends actually meet are given by the condition </p>
<p>
<p class="ql-center-displayed-equation" style="line-height: 37px;"><span class="ql-right-eqno"> (1) </span><span class="ql-left-eqno"> &nbsp; </span><img src="http://www.anujvarma.com/wp-content/ql-cache/quicklatex.com-4616d467ce13e1bee2e45c66b0226425_l3.png"class="ql-img-displayed-equation" alt="&#92;&#98;&#101;&#103;&#105;&#110;&#123;&#101;&#113;&#117;&#97;&#116;&#105;&#111;&#110;&#42;&#125;&#32;&#32;&#124;&#120;&#32;&#45;&#32;&#121;&#124;&#92;&#108;&#101;&#113;&#32;&#92;&#102;&#114;&#97;&#99;&#123;&#49;&#125;&#123;&#52;&#125;&#32;&#32;&#92;&#101;&#110;&#100;&#123;&#101;&#113;&#117;&#97;&#116;&#105;&#111;&#110;&#42;&#125;" title="Rendered by QuickLaTeX.com"/></p>
</p>
<h3>Solution</h3>
<p>The intersection of the above band with the unit square gives us the required probability (7/16)</p>
<h3>Related Problems</h3>
<ol>
<li>Two points A and B are thrown at random onto a unit segment of the x axis. Find the probability that the length of the segment will be smaller than the distance between the origin and the nearest point</li>
<li>Buffon’s needle problem –A plane is ruled with parallel straight lines a distance <em>a </em>apart. A needle of length <em>l&nbsp; </em>where <em>l &lt; a</em>&nbsp; is thrown on the plane at random. Find the probability that the needle will hit any of the lines.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.anujvarma.com/a-probability-problem-will-these-two-friends-ever-meet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sonia breaks her silence – and with it her innocence</title>
		<link>http://www.anujvarma.com/sonia-breaks-her-silence-and-with-it-her-innocence/</link>
		<comments>http://www.anujvarma.com/sonia-breaks-her-silence-and-with-it-her-innocence/#comments</comments>
		<pubDate>Thu, 22 Dec 2011 09:13:19 +0000</pubDate>
		<dc:creator>Anuj Varma</dc:creator>
				<category><![CDATA[India]]></category>
		<category><![CDATA[sonia gandhi anna hazare corruption]]></category>

		<guid isPermaLink="false">http://www.anujvarma.com/sonia-breaks-her-silence-and-with-it-her-innocence/</guid>
		<description><![CDATA[Sonia Gandhi finally broke her silence on Anna Hazare. She defended the draft put forth by her partymen – and asked Anna to do the same. Anyone who has been following this movement knows that the current draft leaves out &#8230; <a href="http://www.anujvarma.com/sonia-breaks-her-silence-and-with-it-her-innocence/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Sonia Gandhi finally broke her silence on Anna Hazare. She defended the draft put forth by her partymen – and asked Anna to do the same. Anyone who has been following this movement knows that the current draft leaves out a key piece of legislation. In fact, the left out piece is so key – that it would be like leaving out the engine from a new car. You might be tempted by the clean, shiny exterior and leather seats – but the minute you try to start the car, it will prove to be a non-starter. The same holds true for the draft put forth by Sonia’s Congress (which leaves the investigation agency out of the LokPal and under the ruling party).&nbsp; </p>
<p>Up till now, Sonia Gandhi had maintained a distant silence. Her silence at least gave her the benefit of doubt. The hope that perhaps, somewhere in her mind, she saw the Hazare movement as a genuine attempt to tackle corruption. That benefit of doubt can no longer be extended to Mrs. Gandhi. She has come out with blazing guns – just like her son Rahul did a few weeks ago. Perhaps she forgets that the Hazare movement effectively ruined <a href="http://cut.ms/bsUN">her son’s image</a> – and has perhaps jeopardized his chances of ever becoming P.M. The lesson to be learnt here was that it wasn’t <em>Anna </em>versus <em>Rahul. </em>It was <em>corruption crusaders </em>versus opponents of the crusade. And the crusaders were not limited to Anna Hazare and his supporters. It included, in large part, all of India’s population – a unification feat that is not easy to replicate in a country as diverse as India. So – when Rahul came out in opposition to Anna Hazare, he came out in opposition to the Indian populace. He went instantly from &#8216;<em>future PM’ </em>to ‘<em>just another politician’. </em></p>
<p>One would hope that Senior Congress leaders would have learnt their lesson from this fall of the mighty. Unfortunately, Sonia Gandhi is also treading the same swamp waters as her son. Her attack on Anna – no matter how compartmentalized it may be – will seem as an attack on Indians all over the world. She will witness the same fall from grace as her son. Not because she tried to tackle Anna – but because she failed to recognize the strength of his movement.&nbsp; Because she tried to <em>fool </em>the Indian people with a watered down draft that even a 6 year old could see through.</p>
<p>Tragically, the only reason that Sonia could possibly be opposed to leaving the CBI out of the LokPal is the same reason as any other politician’s. To avoid going to jail! They know that giving this independent power to the CBI will result in some ‘big fish’ landing behind bars. In fact, without this power, the Lokpal bill is meaningless. Sonia realizes this as well as any other party member – and wants to dilute it.&nbsp; This dilution effort is as good as a confession of guilt. Sonia has broken her silence – and with it her innocence.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anujvarma.com/sonia-breaks-her-silence-and-with-it-her-innocence/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Interesting experiences of an NRI (Mohan) who returned to India</title>
		<link>http://www.anujvarma.com/interesting-experiences-of-an-nri-mohan-who-returned-to-india/</link>
		<comments>http://www.anujvarma.com/interesting-experiences-of-an-nri-mohan-who-returned-to-india/#comments</comments>
		<pubDate>Thu, 15 Dec 2011 14:31:38 +0000</pubDate>
		<dc:creator>Anuj Varma</dc:creator>
				<category><![CDATA[India]]></category>

		<guid isPermaLink="false">http://www.anujvarma.com/?p=1107</guid>
		<description><![CDATA[Mohan&#8217;s Musings
]]></description>
			<content:encoded><![CDATA[<p><a href="http://mohankaus.blogspot.com/">Mohan&#8217;s Musings</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.anujvarma.com/interesting-experiences-of-an-nri-mohan-who-returned-to-india/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Recovering from (a bad) Tennis Elbow</title>
		<link>http://www.anujvarma.com/recovering-from-a-bad-tennis-elbow/</link>
		<comments>http://www.anujvarma.com/recovering-from-a-bad-tennis-elbow/#comments</comments>
		<pubDate>Mon, 05 Dec 2011 19:26:28 +0000</pubDate>
		<dc:creator>Anuj Varma</dc:creator>
				<category><![CDATA[Diet, Health]]></category>

		<guid isPermaLink="false">http://www.anujvarma.com/recovering-from-a-bad-tennis-elbow/</guid>
		<description><![CDATA[I had what was considered grade 3 tennis elbow (grade 4 is the worst and requires surgery). Like everyone out there, I tried EVERYTHING! From steroid shots to prolotherapy to physiotherapy (from one of India’s best). While I did get &#8230; <a href="http://www.anujvarma.com/recovering-from-a-bad-tennis-elbow/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I had what was considered grade 3 tennis elbow (grade 4 is the worst and requires surgery). Like everyone out there, I tried EVERYTHING! From steroid shots to prolotherapy to physiotherapy (from one of India’s best). While I did get some relief, the weakness (and pain) in the elbow joint persisted. I was sure that if I tried to lift anything (even a light object), the pain would return.</p>
<p>Finally, I went to an orthopedic (who happens to be a friend of my father’s). He first explained why this was happening. Overuse. He then explained that every muscle in the hand and the wrist is connected to this same elbow joint. Which is why, when one develops tennis elbow – any movement from the hand-up hurts like hell. His advice was simple – give the elbow <em>complete</em> rest. By complete – he meant complete. Put it in a sling for a week and do not use it at all! Alternatively, if this was unacceptable, I could wear a special elbow brace. This would let me carry on mild daily activities (like computer keyboard) – but, instead of the elbow joint, the brace would absorb the impact.</p>
<p><strong>On Surgery</strong></p>
<p>An interesting thing the orthopedic told me was that surgery simply detaches the muscles from the elbow joint. Therefore – the pain goes away. Not an ideal solution.</p>
<p><strong>On Prolotherapy</strong></p>
<p>I know there are people who swear by this alternative treatment – but I have to say, it did not work for me. It seemed to numb the pain for a while (that was just the ultrasound gel). However, the next day onwards, I could sense no improvement. It is supposed to take a week to 2 weeks. Two weeks down the road, still no improvement. And since this was out of pocket, I felt a good $500 go down the drain for zero relief.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anujvarma.com/recovering-from-a-bad-tennis-elbow/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting out of your own way – The secret to overcoming obstacles</title>
		<link>http://www.anujvarma.com/getting-out-of-your-own-way-the-secret-to-overcoming-obstacles/</link>
		<comments>http://www.anujvarma.com/getting-out-of-your-own-way-the-secret-to-overcoming-obstacles/#comments</comments>
		<pubDate>Sat, 03 Dec 2011 19:07:58 +0000</pubDate>
		<dc:creator>Anuj Varma</dc:creator>
				<category><![CDATA[Buddhism]]></category>

		<guid isPermaLink="false">http://www.anujvarma.com/getting-out-of-your-own-way-the-secret-to-overcoming-obstacles/</guid>
		<description><![CDATA[To do anything big requires courage. Courage requires getting out of your own way. Too often, the only thing holding us back is our own self. To overcome this obstacle, we need to figure out a way to ‘remove’ ourselves &#8230; <a href="http://www.anujvarma.com/getting-out-of-your-own-way-the-secret-to-overcoming-obstacles/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>To do anything big requires courage. Courage requires getting out of your own way. Too often, the only thing holding us back is our own self. To overcome this obstacle, we need to figure out a way to ‘remove’ ourselves from the act.&nbsp; </p>
<h3>How do we get out of our own way?</h3>
<h4>Putting the <em>action</em> in perspective</h4>
<p>This is best done by visualizing your life as a whole – and this particular act as a small part of that life stream. This helps put the action in perspective – and doesn’t let you get overpowered by the thought of performing it.</p>
<h4>Putting <em>fear</em> in its own place</h4>
<p>Chances are that whatever you are trying to do (that requires courage) is something that you enjoy doing (running your business, taking on a new challenge etc.). Try to get to a point where you see your love for the job overcoming the fears associated with it (fear of criticism, fear of failure etc.). That positivity helps put the fear ‘in its place’. Instead of overpowering you, the fear is relegated to just a ‘concern’ – not worth preventing you from undertaking your action.</p>
<h3>Summary</h3>
<p>Do you have important things to do – but find yourself afraid of getting started?&nbsp; Try to figure out if you are getting in your own way or not. Chances are you probably are. Try to get out of your own way by putting the action in perspective – as well as your fear in its own place.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anujvarma.com/getting-out-of-your-own-way-the-secret-to-overcoming-obstacles/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What businesses can learn from flash mobs</title>
		<link>http://www.anujvarma.com/what-businesses-can-learn-from-flash-mobs/</link>
		<comments>http://www.anujvarma.com/what-businesses-can-learn-from-flash-mobs/#comments</comments>
		<pubDate>Sat, 03 Dec 2011 18:39:37 +0000</pubDate>
		<dc:creator>Anuj Varma</dc:creator>
				<category><![CDATA[In the workplace]]></category>
		<category><![CDATA[flash mobs and business]]></category>
		<category><![CDATA[overcoming fear]]></category>

		<guid isPermaLink="false">http://www.anujvarma.com/what-businesses-can-learn-from-flash-mobs/</guid>
		<description><![CDATA[Some qualities of Flash Mob performers
A Flash Mob consists of a group of dancers who come together (seemingly impromptu) and start performing. What do these people share (in addition to an obvious love for dance)? They have all overcome the &#8230; <a href="http://www.anujvarma.com/what-businesses-can-learn-from-flash-mobs/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h3>Some qualities of Flash Mob performers</h3>
<p>A Flash Mob consists of a group of dancers who come together (seemingly impromptu) and start performing. What do these people share (in addition to an obvious love for dance)? They have all overcome the fear of public display!&nbsp; Think about it. You may be a good dancer – but chances are you would not be able to dance on a street full of people. To get to that stage, a certain fear needs to be overcome. This fear is primarily self-induced. In other words, you yourself are the main obstacle standing in your way. Once you get out of your own way, you tend to lose this fear. It helps to know that you are not alone – and others are going to be part of the same event. Still – the first step to being a flash mob performer is the conquest of this fear.</p>
<p>And while a flash mob performance appears to be an <em>impromptu </em>event, in reality, it is quite the contrary. Not only is event planned well in advance, but sufficient practice and rehearsals constitute part of the plan. The exact venue is always kept secret – and only shared with the media (to ensure coverage) as well as the police (to ensure security). The effect of this secretive mode of planning is that, on the d-day, it appears as a completely <em>impromptu </em>event. Which, in fact, adds to its appeal. The whole effect is that of – </p>
<blockquote><p>wow – how could something so ad-hoc and unplanned be so eye-catching and well choreographed? These guys must be good!</p>
</blockquote>
<h3>What does this have to do with business events?</h3>
<p>Businesses need to plan their events in a similar fashion. They need to plan diligently (rehearse the flash mob event), they need to create a sense of secrecy around it – and they need to pull off the event with perfection. Moreover, they need to overcome a certain fear – a fear of criticism – public criticism. Nothing ventured, nothing gained. One company that captured all of the above in all its releases is APPLE.&nbsp; Each release of an apple product almost feels like a flash mob. Prior to a release, it has the same sense of excitement built on secrecy. Post release, it leaves everyone with the same <em>wow </em>factor as a flash mob event. Businesses can learn a few things from flash mobs – would you agree?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anujvarma.com/what-businesses-can-learn-from-flash-mobs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Superfast rendering of UI data (in WinForms and ASP.NET)</title>
		<link>http://www.anujvarma.com/superfast-rendering-of-ui-data-in-winforms-world-2-2/</link>
		<comments>http://www.anujvarma.com/superfast-rendering-of-ui-data-in-winforms-world-2-2/#comments</comments>
		<pubDate>Sat, 19 Nov 2011 10:12:54 +0000</pubDate>
		<dc:creator>Anuj Varma</dc:creator>
				<category><![CDATA[High Performance WinForms Apps]]></category>
		<category><![CDATA[displaying large quantities of data]]></category>
		<category><![CDATA[displaying large volumes of data]]></category>
		<category><![CDATA[syncfusion grid performance]]></category>
		<category><![CDATA[syncfusion grouping grid]]></category>

		<guid isPermaLink="false">http://www.anujvarma.com/superfast-rendering-of-ui-data-in-winforms-world-2-2/</guid>
		<description><![CDATA[While this post compares the WinForms datagridview with a 3rd party (syncfusion) Grid Control for windows, the same comparison also applies to grids in the ASP.NET world.&#160;&#160; 
&#160; 
Business Data and Grids
Business data tends to organize itself into rows and &#8230; <a href="http://www.anujvarma.com/superfast-rendering-of-ui-data-in-winforms-world-2-2/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>While this post compares the WinForms datagridview with a 3rd party (syncfusion) Grid Control for windows, the same comparison also applies to grids in the ASP.NET world.&nbsp;&nbsp; </p>
<p><a href="http://www.anujvarma.com/wp-content/uploads/aspdotnet_grid.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="aspdotnet_grid" border="0" alt="aspdotnet_grid" src="http://www.anujvarma.com/wp-content/uploads/aspdotnet_grid_thumb.png" width="533" height="383"></a>&nbsp; </p>
<h3>Business Data and Grids</h3>
<p>Business data tends to organize itself into rows and columns (witness the success of Lotus123, Excel and other spreadsheet software). </p>
<h3>Windows DataGridView </h3>
<p>For the .NET UI developer, the Windows <a title="DataGridView Class" href="http://cut.ms/Rok">DataGridView</a> is indispensible in that it provides a quick way to organize business data into rows and columns. Sorting, Paging etc. are usually either built in or fairly straightforward to implement. Going beyond the basic sorting (e.g. <a href="http://cut.ms/bqSN">multiple column sort</a>) or basic grouping (e.g. multiple column groups) calls for some serious investment in time. More importantly, as we shall see in this post, going beyond just a few 100 KBs of <em>bound </em>data, leads to serious performance degradation – making the DataGridView unsuitable for enterprise level grid/tabular data applications.</p>
<h3>Object Binding</h3>
<p>Object binding refers to the ability to <em>bind </em>a control to a custom data type (your domain objects). In pre-object binding days, one would bind a control directly to the raw data (e.g. an int <em>CustomerID</em> and a string <em>CustomerName</em> retrieved from the datasource). This was a cumbersome approach since most of the data could logically be grouped into custom data types (e.g. <em>Customer</em>). The User Interface was mainly interested in displaying the domain types (e.g. Customer) and less interested in native data types such as ints and strings. This led to the development of object-binding as an alternative to older raw data-binding.</p>
<p>A typical datagridview application that uses object binding will involve the following steps: </p>
<ol>
<li>Fetching Data (usually using ADO.NET and a DataReader/DataTable/DataSet combination).
<li>Storing the fetched data in a local collection (typically an IList&lt;T&gt; where T represents your custom domain object e.g. IList&lt;Customer&gt;).
<li>Converting the IList&lt;Customer&gt; to a BindingList&lt;Customer&gt;
<li>Binding the BindingList to the datagridview </li>
</ol>
<p>For a detailed walkthrough of custom object binding to a datagridview, see this MSDN magazine <a href="http://cut.ms/bqSx">article</a>.</p>
<h3><em>Bound</em> versus <em>Virtual</em> Display Modes</h3>
<p>By default, most datagridview developers use a Display mode called <em>Bound. </em>In this display mode, the data in the grid is automatically bound to the data in the datasource. This means that the grid view control handles all aspects of fetching the data as well as displaying the data. While this offers convenience, it is the main reason for slower display performance on the DGV. Fortunately, there is another display mode available to address this problem. This mode is known as the <em>virtual </em>display mode. In this display mode, instead of being bound to the entire datasource, the grid is essentially bound to a small subset (a cached portion) of the datasource. This small subset is the set of data should match the data that is visible on the grid (the exact amount of data is under the programmer’s control). Whenever a user wants to see more data (scrolls the grid), that data is fetched from the datasource, placed into cache – and returned to the grid from the cache. This way, only a small amount of data is ever <em>bound </em>to the grid – and even that only through a memory based cache.&nbsp; This alleviates a lot of issues with the Windows DataGridView – including slow UI refreshes, locked UIs etc.</p>
<h3>Windows DataGridView’s <em>Virtual</em> Display Mode </h3>
<pre>
<blockquote>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #008000">// Enable virtual mode.</span>
</pre>
</blockquote>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">            <span style="color: #0000ff">this</span>.dataGridView1.VirtualMode = <span style="color: #0000ff">true</span>;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">            <span style="color: #008000">// Connect the virtual-mode events to event handlers. </span>
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">            <span style="color: #0000ff">this</span>.dataGridView1.CellValueNeeded += <span style="color: #0000ff">new</span>
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">                DataGridViewCellValueEventHandler(dataGridView1_CellValueNeeded);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">          </pre>
</pre>
<p>While the <a title="DataGridView Class" href="http://cut.ms/Rok">DataGridView</a> control is flexible enough to display any IList as its datasource, it starts running into some performance problems for large volumes of data. The <em>Virtual </em>mode in the Windows DataGridView control was designed for just such a purpose – to handle refreshes of large volumes of data. It does this by postponing the rendering of the entire data all at once – and only renders a fixed number of rows and columns at a time. As one tries to scroll down (or up), new data is rendered at that very instant – using predefined events (CellValueNeeded event in the DataGridView). </p>
<h3>For even larger volumes of data..</h3>
<p>&nbsp; While the <em>virtual </em>display mode in the DataGridView offers an option to display lots of data without slowing down refresh rates, even this powerful mode starts showing sluggishness for larger amounts of data (several hundred MBs of data). What is one to do if one needs to continue displaying data in a grid – and the underlying datasource consists of several hundred(s) MBs of data? </p>
<h3>Enter Syncfusion </h3>
<p>&nbsp; Syncfusion is a 3rd Party UI library – which contains several advanced controls in its toolbox. It offers a <a href="http://cut.ms/Rol">GridControl</a> with all the basic grid display capabilities. In addition to the basic gridcontrol,&nbsp; it offers something called a <a href="http://cut.ms/Rom">GridGroupingControl</a> – which is a GridControl on steroids. (NOTE: The difference between the GridGroupingControl and the GridControl in Syncfusion is basically in the set of features – the GridGroupingControl has a richer set of features. Performance-wise, they are both comparable). The rest of this post summarizes some of my initial experiences as a Syncfusion developer – both in terms of performance as well as built-in capabilities.</p>
<pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"></pre>
</pre>
<h3>Syncfusion Grid Grouping Control Features:&nbsp; Grouping by Multiple Columns, Nested Grids (Hierarchical data)</h3>
<p><a href="http://www.anujvarma.com/wp-content/uploads/NestedTableHierarchy_larger.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="NestedTableHierarchy_larger" border="0" alt="NestedTableHierarchy_larger" src="http://www.anujvarma.com/wp-content/uploads/NestedTableHierarchy_larger_thumb.png" width="439" height="244"></a> </p>
<p>For instance, if one is interested in grouping by not one – but multiple columns, the grouping grid does it with just a couple of lines of code. If one is interested in nested grids (to display hierarchical data for example), Syncfusion’s GridGroupingControl provides that out of the box as well (see screenshot above). Note that one can build the same nested table functionality in the Windows DataGridView (using the example shown <a href="http://cut.ms/bqSw">here</a>). If one is interested in sorting by more than one column, Syncfusion GridGroupingControl provides that out of the box as well (whereas one needs to custom build this in the Windows DataGridView as shown in <a href="http://cut.ms/bqSN">this article</a>). </p>
<h3>Syncfusion Grid Control (and Grid Grouping Control)&nbsp; – Performance</h3>
<p>&nbsp; However, the main reason our team chose Syncfusion was simple – <em>performance</em>. Syncfusion provides a <a href="http://cut.ms/Rol">GridControl</a> class which also has a <em>virtual mode</em> built in.&nbsp; The virtual mode in Syncfusion’s GridControl works in a similar fashion to Windows DataGridView – by rendering more rows and columns as the user tries to scroll up or down on the grid. The actual events that Syncfusion uses are QueryCellInfo and QueryRowCount (full source code available at the of this post). The snippet below shows the main events that the gridControl needs to have handled.</p>
<pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">            <span style="color: #008000">// Enable virtual mode.</span>
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">            <span style="color: #0000ff">this</span>.dataGridView1.VirtualMode = <span style="color: #0000ff">true</span>;
</pre>
</pre>
<pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">            <span style="color: #0000ff">this</span>.gridControl1.QueryCellInfo += <span style="color: #0000ff">new</span> Syncfusion.Windows.Forms.Grid.GridQueryCellInfoEventHandler(<span style="color: #0000ff">this</span>.gridControl1_QueryCellInfo);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">            <span style="color: #0000ff">this</span>.gridControl1.QueryRowCount += <span style="color: #0000ff">new</span> Syncfusion.Windows.Forms.Grid.GridRowColCountEventHandler(<span style="color: #0000ff">this</span>.gridControl1_QueryRowCount);</pre>
</pre>
<h3>Sample Experiment – Comparing Refresh Rates – DataGridView versus Syncfusion Grid </h3>
<p>&nbsp; The source code (included below) uses a simple ArrayList (of Customer objects) – and lets you experiment with the performance of the DataGridView as the number of objects grows. In the sample code, the list of Customers is set to a size of 10,000. At this size, the performance difference between the Windows DatagridView and Syncfusion’s GridControl are already visible. If you try a larger size list, the differences will be even more evident. </p>
<h3>Load Time versus Rendering Time</h3>
<p>The real test of how fast data is displayed on the grid – is the <em>rendering </em>time. We are less concerned here with the data retrieval time (for e.g. – retrieving data from an ADO.NET source) – than with the time it takes to display thousands of rows of data.&nbsp; When one runs the two grids (WinForms dgv and Syncfusion’s gridcontrol) side by side, for the same set of data (see the sample solution below), one can see by just plain visual inspection, the Windows DataGridView renders a lot slower than Syncfusion’s GridControl. </p>
<h3>Summary</h3>
<p>This article (based on my experience as a Syncfusion developer) shows a side by side performance experiment of the WinForms DataGridView and Syncfusion’s GridControl. Using each of these grids to display the exact same data (10,000 unique customer data records), one can see the different rendering speeds. WinForms’ DataGridView starts deteriorating in performance at just a few hundred KBs of display data – in spite of using its own fastest display mode – the <em>virtual </em>display mode.</p>
<p>&nbsp;<a href="http://cut.ms/Ron">Syncfusion’s</a> GridControl offers a faster (superfast) alternative to the WinForms DataGridView. In addition to speed, the grid control offers sophisticated data manipulation features such as nested grids (nested tables), pivot tables, multiple column sorts etc. Other vendors (Infragistics, Telerik etc.) offer similar grid controls, however, in our initial performance centric comparisons, syncfusion’s grid control seemed to be a clear winner. The choice of Syncfusion mentioned above is somewhat biased &#8211; as my experience as a Syncfusion developer is more extensive than as a Telerik or Infragistics developer. </p>
<p>If your business data is in the hundreds of MBs (as ours was) and needs to be bound to UI controls, chances are you will outgrow the built-in WinForms controls very quickly. You will need to start looking at 3rd party vendors like Syncfusion and Infragistics to provide you with the UI performance that your application needs.</p>
<h3>Source Code </h3>
<p>Download Source Code (Need to <a href="http://cut.ms/bqSO">download</a> and install Syncfusion Essential Studio <a href="http://cut.ms/bqSP">Windows Forms Edition 7.3.X</a> or above)&nbsp;
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:F60BB8FA-6F02-4999-8F5E-9DD4E92C4DA7:50dd070e-8573-4523-a579-86c4a97ed00c" class="wlWriterSmartContent">
<div><a href="http://www.anujvarma.com/wp-content/uploads/SyncfusionGridPerformance.zip" target="_self">SyncfusionGridPerformance.zip</a></div>
</div>
</p>
<h3>About the Author</h3>
<p>&nbsp; Anuj Varma is a Microsoft .NET architect specializing in high-performance applications. His specific expertise in the .NET framework architecture as well as 3rd party controls (Syncfusion development) built around the framework,&nbsp; makes him a sought after performance expert for .NET applications.&nbsp; Anuj’ experience as a Syncfusion developer makes him a sought after Syncfusion expert. He continues to specialize in Syncfusion’s Essential Suite for building sophisticated web and desktop applications. Most recently, he has worked on an ASP.NET revamp of dell.com as well as a WinForms app used to map Ocean floors (Petrel). Both these applications were built with performance (UI performance as well as Data Access Layer performance) as a key driver.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anujvarma.com/superfast-rendering-of-ui-data-in-winforms-world-2-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows DataGridView – Improving the Data Display (Refresh) Performance</title>
		<link>http://www.anujvarma.com/windows-datagridview-improving-the-data-display-refresh-performance/</link>
		<comments>http://www.anujvarma.com/windows-datagridview-improving-the-data-display-refresh-performance/#comments</comments>
		<pubDate>Sun, 13 Nov 2011 11:47:49 +0000</pubDate>
		<dc:creator>Anuj Varma</dc:creator>
				<category><![CDATA[High Performance WinForms Apps]]></category>
		<category><![CDATA[.net datagrid]]></category>
		<category><![CDATA[.net winforms grid]]></category>
		<category><![CDATA[data grid performance]]></category>
		<category><![CDATA[data grid view windows]]></category>
		<category><![CDATA[datagridview performance]]></category>
		<category><![CDATA[dgv .net]]></category>
		<category><![CDATA[refresh rate datagridview]]></category>
		<category><![CDATA[slow refresh rate datagridview]]></category>

		<guid isPermaLink="false">http://www.anujvarma.com/windows-datagridview-improving-the-data-display-refresh-performance/</guid>
		<description><![CDATA[&#160; The DataGridView is used everywhere – both in ASP.net apps as well as WinForms apps. A quick google search will reveal the scale of users affected by the slow refresh rate on the DataGridView control.&#160; How the data is &#8230; <a href="http://www.anujvarma.com/windows-datagridview-improving-the-data-display-refresh-performance/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>&nbsp; The DataGridView is used everywhere – both in ASP.net apps as well as WinForms apps. A quick google search will reveal the scale of users affected by the slow refresh rate on the DataGridView control.&nbsp; How the data is displayed is dictated by a property called the <em>Display Mode. </em>The <em>Display Mode </em>that most datagridview users opt for is the <em>Bound mode.</em></p>
<h3>An object-bound datagridview</h3>
<p>Object binding refers to the ability to <em>bind </em>a control to a custom data type (your domain objects). In pre-object binding days, one would bind a control directly to the raw data (e.g. an int <em>CustomerID</em> and a string <em>CustomerName</em> retrieved from the datasource). This was a cumbersome approach since most of the data could logically be grouped into custom data types (e.g. <em>Customer</em>). The User Interface was mainly interested in displaying the domain types (e.g. Customer) and less interested in native data types such as ints and strings. This led to the development of object-binding as an alternative to older raw data-binding.</p>
<p>A typical datagridview application that uses object binding will involve the following steps: </p>
<ol>
<li>Fetching Data (usually using ADO.NET and a DataReader/DataTable/DataSet combination).</li>
<li>Storing the fetched data in a local collection (typically an IList&lt;T&gt; where T represents your custom domain object e.g. IList&lt;Customer&gt;).</li>
<li>Converting the IList&lt;Customer&gt; to a BindingList&lt;Customer&gt; </li>
<li>Binding the BindingList to the datagridview</li>
</ol>
<p>For a detailed walkthrough of custom object binding to a datagridview, see this MSDN magazine <a href="http://cut.ms/bqSx">article</a>.</p>
<h3><em>Bound</em> Display Mode</h3>
<p>For object bound DGVs (datagridviews), the ‘Bound’ mode is the most commonly used display mode. In this mode, the datagridview control is automatically bound to the source of the data – and any changes to the source of the data cause refreshes of the various UI elements of the grid (columns, rows etc.). This offers a degree of convenience that is appealing, at least for small volumes of data. This <em>Bound </em>mode kicks into effect whenever you set the <em>Datasource </em>property on the&nbsp; datagridview as shown in the snippet below. </p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:407f6465-9b22-4129-b6a3-5dbbaf9d8ae1" class="wlWriterSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Code Snippet</div>
<div style="background: #ddd; max-height: 300px; overflow: auto">
<ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;">
<li><span style="color:#008000">// Define your BindingList</span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#2b91af">BindingList</span>&lt;<span style="color:#0000ff">object</span>&gt; bindableDataSource = <span style="color:#0000ff">new</span> <span style="color:#2b91af">BindingList</span>&lt;<span style="color:#0000ff">object</span>&gt;();</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#008000">// Add some data to the bindingList</span></li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#2b91af">BindingList</span>&lt;<span style="color:#0000ff">object</span>&gt; list = CreateData();</li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff">foreach</span> (<span style="color:#0000ff">object</span> item <span style="color:#0000ff">in</span> list)</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;{</li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;bindableDataSource.Add(item);</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}</li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#008000">// This actually &#39;binds&#39; the gridview to the BindingList. Any changes to the BindingList from here on affect the gridview.</span></li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#008000">// For e.g. &#8211; The &#39;bound&#39; gridview would refresh its layout every time a new item is added to this BindingList</span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;dataGridView1.DataSource = bindableDataSource;</li>
</ol></div>
</p></div>
</p></div>
<h3>The Problem with <em>Bound </em>display mode</h3>
<p>The first indications of problems with the <em>bound </em>mode are visible as soon as you start adding additional items to the source list (while the grid is bound to it). Note that it is possible to add additional items without binding the grid – and then performing the binding step at the very end – as shown in the snippet above. However, even with this approach, at some point, you may need to add/delete items from the source list – causing unnecessary refreshes. More serious problems with the DataGridView start manifesting themselves as the size of the bound collection grows. For larger sets of data, this problem grows to unacceptable response times.</p>
<h3>Enter Virtual Mode</h3>
<p>By default, most datagridview developers use a Display mode called <em>Bound. </em>In this display mode, the data in the grid is automatically bound to the data in the datasource. This means that the grid view control handles all aspects of fetching the data as well as displaying the data. While this offers convenience, it is the main reason for slower display performance on the DGV. Fortunately, there is another display mode available to address this problem. This mode is known as the <em>virtual </em>display mode. In this display mode, instead of being bound to the entire datasource, the grid is essentially bound to a small subset (a cached portion) of the datasource. This small subset is the set of data should match the data that is visible on the grid (the exact amount of data is under the programmer’s control). Whenever a user wants to see more data (scrolls the grid), that data is fetched from the datasource, placed into cache – and returned to the grid from the cache. This way, only a small amount of data is ever <em>bound </em>to the grid – and even that only through a memory based cache.&nbsp; This alleviates a lot of issues with the Windows DataGridView – including slow UI refreshes, locked UIs etc.</p>
<h3>Quick Conversion from <em>bound </em>to <em>virtual </em>(full source code at the end of this post)</h3>
<p>In your source code, if you are using the <em>bound </em>display mode (happens by default if you set the ‘datasource property) you will be setting the <em>datasource </em>property on your gridview somewhere – e.g. </p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:09575649-dadd-4b2b-afff-5dc249175e1c" class="wlWriterSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Code Snippet</div>
<div style="background: #ddd; max-height: 300px; overflow: auto">
<ol style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;">
<li><span style="color:#0000ff">this</span>.dataGridView1.DataSource = _customers;</li>
</ol></div>
</p></div>
</p></div>
<p>Instead of setting this datasource property, what you will need to do is <em>initialize</em> the grid to use <em>virtual </em>mode. This is shown in the snippet below (full source code included at the end of this post).</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:11b1380f-6c39-4f34-8e10-9eced04a6691" class="wlWriterSmartContent">
<div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Code Snippet</div>
<div style="background: #ddd; max-height: 300px; overflow: auto">
<ol style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;">
<li><span style="color:#0000ff">private</span> <span style="color:#0000ff">void</span> InitializeGrid()</li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;{</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#008000">// Enable virtual mode.</span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff">this</span>.dataGridView1.VirtualMode = <span style="color:#0000ff">true</span>;</li>
<li>&nbsp;</li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#008000">// Connect the virtual-mode events to event handlers. </span></li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff">this</span>.dataGridView1.CellValueNeeded += <span style="color:#0000ff">new</span></li>
<li style="background: #f3f3f3">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#2b91af">DataGridViewCellValueEventHandler</span>(dataGridView1_CellValueNeeded);</li>
</ol></div>
</p></div>
</p></div>
<p>The actual <em>dataGridView1_CellValueNeeded </em>event is where the event to request more data is handled.&nbsp; The included source code below provides a quick implementation of the virtual display mode – which should work for simple use cases. For a <a href="http://cut.ms/bqSH">full walkthrough</a> on a virtual mode implementation, see MSDN.</p>
<h3>What if the Virtual Mode is still sluggish?</h3>
<p>If the performance of virtual mode is still sluggish for your data (if you have several thousands of rows of data), chances are you need to look elsewhere. There are several 3rd party grid controls on the market – including Infragistics, Syncfusion and Telerik. One such grid that I have worked with extensively is Syncfusion’s Grid Control. On my project, we were handling several hundred MBs of data in the grid – with refreshes occurring in real-time or near real-time (i.e. no sluggishness).&nbsp; A performance comparison is detailed in an <a href="http://cut.ms/bqSI">earlier post</a>.</p>
<p>In addition to the speed, you also get a host of features that I like to call <em>Grid on Steroids </em>features. These include <em>nested grids </em>(which make it possible to efficiently display hierarchical data), multiple column sorts (which isn’t available out of the box in Windows DataGridView – but can be <a href="http://cut.ms/bqSN">custom built</a>), pivot tables and more.</p>
</p>
<h3>Summary</h3>
<p>If you are witnessing slow rendering (sluggish rendering) of your datagridview in your WinForms (or ASP.NET ) application, chances are you are using automatic binding (<em>bound </em>display mode). Chances are that you will experience a significant benefit from trying the <em>virtual </em>display mode built into the gridview. This display mode <em>binds </em>to a smaller, cached subset of the full data, allowing quicker UI refreshes. The sample attached here shows a grid using the <em>bound </em>mode and another grid using <em>virtual </em>mode (both with identical 10000 rows of customer data). Even with this simple sample of a few 100 KBs of data, a noticeable difference can be seen (by visual inspection) when one tries to scroll down the grid to view more rows. The refresh rate of the <em>virtual </em>mode grid clearly wins out.&nbsp; If you find the <em>virtual </em>mode also insufficient for your application’s volume of data, you might need something like <a href="http://cut.ms/bqSI">the syncfusion grid</a>. </p>
<h3>Source Code</h3>
<p>Download Full Solution
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:F60BB8FA-6F02-4999-8F5E-9DD4E92C4DA7:fcb41de7-8b44-425e-8a55-db79b2c500ec" class="wlWriterSmartContent">
<div><a href="http://www.anujvarma.com/wp-content/uploads/VirtualMode_DataGridView.zip" target="_self">VirtualMode_DataGridView.zip</a></div>
</div>
<h3>About the Author</h3>
<p>&nbsp; Anuj Varma is a Microsoft .NET architect specializing in high-performance applications. His specific expertise in the .NET framework architecture as well as 3rd party controls (such as Syncfusion) built around the framework,&nbsp; makes him a sought after performance expert for .NET applications. Most recently, he has worked on an ASP.NET revamp of dell.com as well as a WinForms app used to map Ocean floors (Petrel). Both these applications were built with performance (UI performance as well as Data Access Layer performance) as a key driver. In addition to WinForms and ASP.NET apps, Anuj works hands-on in the WCF and Azure arena to bring performance to existing SOA apps. Some of Anuj’s personal websites include <em><a href="http://cut.ms/bqSQ">anujvarma.com</a>, </em>&nbsp;<a href="http://cut.ms/bqSR"><em>AspDotnetArchitect.com</em></a><em> and </em><a href="http://cut.ms/blI1"><em>RecruitersToAvoid.com</em></a><em>.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.anujvarma.com/windows-datagridview-improving-the-data-display-refresh-performance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Superfast rendering of UI data (in WinForms and ASP.NET)</title>
		<link>http://www.anujvarma.com/superfast-rendering-of-ui-data-in-winforms-world-2/</link>
		<comments>http://www.anujvarma.com/superfast-rendering-of-ui-data-in-winforms-world-2/#comments</comments>
		<pubDate>Sun, 13 Nov 2011 02:44:50 +0000</pubDate>
		<dc:creator>Anuj Varma</dc:creator>
				<category><![CDATA[High Performance WinForms Apps]]></category>
		<category><![CDATA[displaying large quantities of data]]></category>
		<category><![CDATA[displaying large volumes of data]]></category>
		<category><![CDATA[syncfusion grid performance]]></category>
		<category><![CDATA[syncfusion grouping grid]]></category>

		<guid isPermaLink="false">http://www.anujvarma.com/superfast-rendering-of-ui-data-in-winforms-world-2/</guid>
		<description><![CDATA[While this post compares the WinForms datagridview with a 3rd party (syncfusion) Grid Control for windows, the same comparison also applies to grids in the ASP.NET world.&#160;&#160; 
&#160; 
Business Data and Grids
Business data tends to organize itself into rows and &#8230; <a href="http://www.anujvarma.com/superfast-rendering-of-ui-data-in-winforms-world-2/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>While this post compares the WinForms datagridview with a 3rd party (syncfusion) Grid Control for windows, the same comparison also applies to grids in the ASP.NET world.&nbsp;&nbsp; </p>
<p><a href="http://www.anujvarma.com/wp-content/uploads/aspdotnet_grid.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="aspdotnet_grid" border="0" alt="aspdotnet_grid" src="http://www.anujvarma.com/wp-content/uploads/aspdotnet_grid_thumb.png" width="533" height="383"></a>&nbsp; </p>
<h3>Business Data and Grids</h3>
<p>Business data tends to organize itself into rows and columns (witness the success of Lotus123, Excel and other spreadsheet software). </p>
<h3>Windows DataGridView </h3>
<p>For the .NET UI developer, the Windows <a title="DataGridView Class" href="http://cut.ms/Rok">DataGridView</a> is indispensible in that it provides a quick way to organize business data into rows and columns. Sorting, Paging etc. are usually either built in or fairly straightforward to implement. Going beyond the basic sorting (e.g. multiple column sort) or basic grouping (e.g. multiple column groups) calls for some serious investment in time. More importantly, as we shall see in this post, going beyond just a few 100 KBs of <em>bound </em>data, leads to serious performance degradation – making the DataGridView unsuitable for enterprise level grid/tabular data display centric applications.</p>
<h3>Object Binding</h3>
<p>Object binding refers to the ability to <em>bind </em>a control to a custom data type (your domain objects). In pre-object binding days, one would bind a control directly to the raw data (e.g. an int <em>CustomerID</em> and a string <em>CustomerName</em> retrieved from the datasource). This was a cumbersome approach since most of the data could logically be grouped into custom data types (e.g. <em>Customer</em>). The User Interface was mainly interested in displaying the domain types (e.g. Customer) and less interested in native data types such as ints and strings. This led to the development of object-binding as an alternative to older raw data-binding.</p>
<p>A typical datagridview application that uses object binding will involve the following steps: </p>
<ol>
<li>Fetching Data (usually using ADO.NET and a DataReader/DataTable/DataSet combination).</li>
<li>Storing the fetched data in a local collection (typically an IList&lt;T&gt; where T represents your custom domain object e.g. IList&lt;Customer&gt;).</li>
<li>Converting the IList&lt;Customer&gt; to a BindingList&lt;Customer&gt; </li>
<li>Binding the BindingList to the datagridview</li>
</ol>
<p>For a detailed walkthrough of custom object binding to a datagridview, see this MSDN magazine <a href="http://cut.ms/bqSx">article</a>.</p>
<h3><em>Bound</em> versus <em>Virtual</em> Display Modes</h3>
<p>By default, most datagridview developers use a Display mode called <em>Bound. </em>In this display mode, the data in the grid is automatically bound to the data in the datasource. This means that the grid view control handles all aspects of fetching the data as well as displaying the data. While this offers convenience, it is the main reason for slower display performance on the DGV. Fortunately, there is another display mode available to address this problem. This mode is known as the <em>virtual </em>display mode. In this display mode, instead of being bound to the entire datasource, the grid is essentially bound to a small subset (a cached portion) of the datasource. This small subset is the set of data should match the data that is visible on the grid (the exact amount of data is under the programmer’s control). Whenever a user wants to see more data (scrolls the grid), that data is fetched from the datasource, placed into cache – and returned to the grid from the cache. This way, only a small amount of data is ever <em>bound </em>to the grid – and even that only through a memory based cache.&nbsp; This alleviates a lot of issues with the Windows DataGridView – including slow UI refreshes, locked UIs etc.</p>
<h3>Windows DataGridView’s <em>Virtual</em> Display Mode </h3>
<pre>
<blockquote>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #008000">// Enable virtual mode.</span>
</pre>
</blockquote>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">            <span style="color: #0000ff">this</span>.dataGridView1.VirtualMode = <span style="color: #0000ff">true</span>;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">            <span style="color: #008000">// Connect the virtual-mode events to event handlers. </span>
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">            <span style="color: #0000ff">this</span>.dataGridView1.CellValueNeeded += <span style="color: #0000ff">new</span>
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">                DataGridViewCellValueEventHandler(dataGridView1_CellValueNeeded);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">          </pre>
</pre>
<p>While the <a title="DataGridView Class" href="http://cut.ms/Rok">DataGridView</a> control is flexible enough to display any IList as its datasource, it starts running into some performance problems for large volumes of data. The <em>Virtual </em>mode in the Windows DataGridView control was designed for just such a purpose – to handle refreshes of large volumes of data. It does this by postponing the rendering of the entire data all at once – and only renders a fixed number of rows and columns at a time. As one tries to scroll down (or up), new data is rendered at that very instant – using predefined events (CellValueNeeded event in the DataGridView). </p>
<h3>For even larger volumes of data..</h3>
<p>&nbsp; While the <em>virtual </em>display mode in the DataGridView offers an option to display lots of data without slowing down refresh rates, even this powerful mode starts showing sluggishness for larger amounts of data (several hundred MBs of data). What is one to do if one needs to continue displaying data in a grid – and the underlying datasource consists of several hundred(s) MBs of data? </p>
<h3>Enter Syncfusion </h3>
<p>&nbsp; Syncfusion is a 3rd Party UI library – which contains several advanced controls in its toolbox. It offers a <a href="http://cut.ms/Rol">GridControl</a> with all the basic grid display capabilities. In addition to the basic gridcontrol,&nbsp; it offers something called a <a href="http://cut.ms/Rom">GridGroupingControl</a> – which is a GridControl on steroids. (NOTE: The difference between the GridGroupingControl and the GridControl in Syncfusion is basically in the set of features – the GridGroupingControl has a richer set of features. Performance-wise, they are both comparable)</p>
<pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"></pre>
</pre>
<h3>Syncfusion Grid Grouping Control Features:&nbsp; Grouping by Multiple Columns, Nested Grids (Hierarchical data)</h3>
<p><a href="http://www.anujvarma.com/wp-content/uploads/NestedTableHierarchy_larger.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="NestedTableHierarchy_larger" border="0" alt="NestedTableHierarchy_larger" src="http://www.anujvarma.com/wp-content/uploads/NestedTableHierarchy_larger_thumb.png" width="439" height="244"></a> </p>
<p>For instance, if one is interested in grouping by not one – but multiple columns, the grouping grid does it with just a couple of lines of code. If one is interested in nested grids (to display hierarchical data for example), Syncfusion’s GridGroupingControl provides that out of the box as well (see screenshot above). Note that one can build the same nested table functionality in the Windows DataGridView (using the example shown <a href="http://cut.ms/bqSw">here</a>). If one is interested in sorting by more than one column, Syncfusion GridGroupingControl provides that out of the box as well (whereas one needs to custom build this in the Windows DataGridView as shown in <a href="http://cut.ms/bqSN">this article</a>). </p>
<h3>Syncfusion Grid Control (and Grid Grouping Control)&nbsp; – Performance</h3>
<p>&nbsp; However, the main reason our team chose Syncfusion was simple – <em>performance</em>. Syncfusion provides a <a href="http://cut.ms/Rol">GridControl</a> class which also has a <em>virtual mode</em> built in.&nbsp; The virtual mode in Syncfusion’s GridControl works in a similar fashion to Windows DataGridView – by rendering more rows and columns as the user tries to scroll up or down on the grid. The actual events that Syncfusion uses are QueryCellInfo and QueryRowCount (full source code available at the of this post). The snippet below shows the main events that the gridControl needs to have handled.</p>
<pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">            <span style="color: #008000">// Enable virtual mode.</span>
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">            <span style="color: #0000ff">this</span>.dataGridView1.VirtualMode = <span style="color: #0000ff">true</span>;
</pre>
</pre>
<pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">            <span style="color: #0000ff">this</span>.gridControl1.QueryCellInfo += <span style="color: #0000ff">new</span> Syncfusion.Windows.Forms.Grid.GridQueryCellInfoEventHandler(<span style="color: #0000ff">this</span>.gridControl1_QueryCellInfo);
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">            <span style="color: #0000ff">this</span>.gridControl1.QueryRowCount += <span style="color: #0000ff">new</span> Syncfusion.Windows.Forms.Grid.GridRowColCountEventHandler(<span style="color: #0000ff">this</span>.gridControl1_QueryRowCount);</pre>
</pre>
<h3>Sample Experiment – Comparing Refresh Rates – DataGridView versus Syncfusion Grid </h3>
<p>&nbsp; The source code (included below) uses a simple ArrayList (of Customer objects) – and lets you experiment with the performance of the DataGridView as the number of objects grows. In the sample code, the list of Customers is set to a size of 10,000. At this size, the performance difference between the Windows DatagridView and Syncfusion’s GridControl are already visible. If you try a larger size list, the differences will be even more evident. </p>
<h3>Load Time versus Rendering Time</h3>
<p>The real test of how fast data is displayed on the grid – is the <em>rendering </em>time. We are less concerned here with the data retrieval time (for e.g. – retrieving data from an ADO.NET source) – than with the time it takes to display thousands of rows of data.&nbsp; When one runs the two grids (WinForms dgv and Syncfusion’s gridcontrol) side by side, for the same set of data (see the sample solution below), one can see by just plain visual inspection, the Windows DataGridView renders a lot slower than Syncfusion’s GridControl. </p>
<h3>Summary</h3>
<p>This article shows a side by side performance experiment of the WinForms DataGridView and Syncfusion’s GridControl. Using each of these grids to display the exact same data (10,000 unique customer data records), one can see the different rendering speeds. WinForms’ DataGridView starts deteriorating in performance at just a few hundred KBs of display data – in spite of using its own fastest display mode – the <em>virtual </em>display mode.</p>
<p>&nbsp;<a href="http://cut.ms/Ron">Syncfusion’s</a> GridControl offers a faster (superfast) alternative to the WinForms DataGridView. In addition to speed, the grid control offers sophisticated data manipulation features such as nested grids (nested tables), pivot tables, multiple column sorts etc. Other vendors (Infragistics, Telerik etc.) offer similar grid controls, however, in our initial performance centric comparisons, syncfusion’s grid control seemed to be a clear winner.</p>
<p>If your business data is in the hundreds of MBs (as ours was) and needs to be bound to UI controls, chances are you will outgrow the built-in WinForms controls very quickly. You will need to start looking at 3rd party vendors like Syncfusion and Infragistics to provide you with the UI performance that your application needs.</p>
<h3>Source Code </h3>
<p>Download Source Code (Need to <a href="http://cut.ms/bqSO">download</a> and install Syncfusion Essential Studio <a href="http://cut.ms/bqSP">Windows Forms Edition 7.3.X</a> or above)&nbsp;
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:F60BB8FA-6F02-4999-8F5E-9DD4E92C4DA7:50dd070e-8573-4523-a579-86c4a97ed00c" class="wlWriterSmartContent">
<div><a href="http://www.anujvarma.com/wp-content/uploads/SyncfusionGridPerformance.zip" target="_self">SyncfusionGridPerformance.zip</a></div>
</div>
</p>
<h3>About the Author</h3>
<p>&nbsp; Anuj Varma is a Microsoft .NET architect specializing in high-performance applications. His specific expertise in the .NET framework architecture as well as 3rd party controls (such as Syncfusion) built around the framework,&nbsp; makes him a sought after performance expert for .NET applications. Most recently, he has worked on an ASP.NET revamp of dell.com as well as a WinForms app used to map Ocean floors (Petrel). Both these applications were built with performance (UI performance as well as Data Access Layer performance) as a key driver. In addition to WinForms and ASP.NET apps, Anuj works hands-on in the WCF and Azure arena to bring performance to existing SOA apps. Some of Anuj’s personal websites include <em><a href="http://cut.ms/bqSQ">anujvarma.com</a>, </em>&nbsp;<a href="http://cut.ms/bqSR"><em>AspDotnetArchitect.com</em></a><em> and </em><a href="http://cut.ms/blI1"><em>RecruitersToAvoid.com</em></a><em>.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.anujvarma.com/superfast-rendering-of-ui-data-in-winforms-world-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VS Compilation Error -The item was specified more than once in the resources parameter</title>
		<link>http://www.anujvarma.com/vs-compilation-error-the-item-was-specified-more-than-once-in-the-resources-parameter/</link>
		<comments>http://www.anujvarma.com/vs-compilation-error-the-item-was-specified-more-than-once-in-the-resources-parameter/#comments</comments>
		<pubDate>Fri, 11 Nov 2011 01:02:48 +0000</pubDate>
		<dc:creator>Anuj Varma</dc:creator>
				<category><![CDATA[Visual Studio Tips, Tricks]]></category>
		<category><![CDATA[resource compilation error Visual Studio VS]]></category>

		<guid isPermaLink="false">http://www.anujvarma.com/vs-compilation-error-the-item-was-specified-more-than-once-in-the-resources-parameter/</guid>
		<description><![CDATA[&#160;
The Issue : Visual Studio throws the following compile time error on a project that includes UI controls (either WinForms or ASP.NET controls). 

The item was specified more than once in the resources parameter. Duplicate items are not supported by &#8230; <a href="http://www.anujvarma.com/vs-compilation-error-the-item-was-specified-more-than-once-in-the-resources-parameter/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<pre>&nbsp;</pre>
<p>The Issue : Visual Studio throws the following compile time error on a project that includes UI controls (either WinForms or ASP.NET controls). </p>
<blockquote>
<p>The item was specified more than once in the resources parameter. Duplicate <em>items</em> are not supported by the &#8220;<em>Resources</em>&#8221; <b>.</b></p>
</blockquote>
<p>Solution: Simply open up the .csproj file – and look for the occurence of the particular resource&nbsp; (item). This resource item <em>name </em>appears in the exact compiler error. In my case, the resource name was SyncfusionVirtualGrid – and my .csproj contained an entry such as:</p>
<pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">  &lt;EmbeddedResource Include="<span style="color: #8b0000">SyncfusionVirtualGrid.resx</span>"&gt;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">      &lt;DependentUpon&gt;SyncfusionVirtualGrid.cs&lt;/DependentUpon&gt;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">    &lt;/EmbeddedResource&gt;
</pre>
<pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">  </pre>
</pre>
<p>Remove this entry from the .csproj file (Alternatively, you can just right click on the .resx file – and delete it from there<em>).</em></p>
<p>This should resolve the compilation error.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anujvarma.com/vs-compilation-error-the-item-was-specified-more-than-once-in-the-resources-parameter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

