title: How can we format group of data in DataGridView of Winform
body: <p>In my Winforms 4.5 app, I am binding a DataGridView to a SQL Server Db table called Products. The table has a column called Category that displays a category the product is in. For example:</p>
  
  <pre><code>C1  P11
  C1  P112
  C2  P21
  C2  P22
  C2  P23
  C3  P31
  ..  ...
  C4  P41
  C4  P42
  ..  ...
  </code></pre>
  
  <p>I would like to set the alternating row style of the DataGridView based on each group (not for each row). So, in the above example, the first two rows (group C1) would have default background color, the next three rows (group C2) would have a dark grey background color, the rows for group C3 would have the default background color, the rows for group C4 would have dark grey background color, and so on. How can I achieve this. Please note that the number of rows in each group would change dynamically based on the data entry by the user; and the demo data shown above is not the real data.</p>
  
  <p>I tried the following two MSDN articles with their examples but they are not quite what I want above:</p>
  
  <ol>
  <li><a href="http://msdn.microsoft.com/en-us/library/txth0a6h(v=vs.110).aspx" rel="nofollow">Set Alternating Row Styles for the Windows Forms DataGridView Control</a></li>
  <li><a href="http://msdn.microsoft.com/en-us/library/z1cc356h(v=vs.80).aspx" rel="nofollow">Customize Data Formatting in the Windows Forms DataGridView Control</a></li>
  </ol>
  
  <p><strong>EDIT</strong>
  In the real data, the categories would not contain numbers in front of them. Real example of categories could be: Fruits, Vegetables, Dairy,...</p>