tags:

views:

116

answers:

2

Hi I have the following data in datagridview in c# winforms:


Column A | Column B | Column C | Group

 Register 1  |       10,00     |       15,00 | Group 1
 Register 2  |       10,00     |       15,00 | Group 1
 Register 3  |       10,00     |       15,00 | Group 2
 Register 4  |       10,00     |       15,00 | Group 2

I want to get this in the following form:


Column A | Column B | Column C

Group 1
Register 1 | 10,00 | 15,00
Register 2 | 10,00 | 15,00
Group 1
Register 3 | 10,00 | 15,00
Register 4 | 10,00 | 15,00

I dont want to use multiple datagridviews

A: 

These steps may possibly help:

Set AutoGenerateColumns to false. Create an additional TextBoxColumn which will display the Grouped column heading. Generate the other columns. Use appropriate queries to bind to the grouped data.

Mamta Dalal
Could you be more specific on "Appropriate Queries". I have all the data into a datatable and dont want to make additional queries to DB. If you have any sample for manipulating from DB, that will be great.
Chinjoo
Can you bind to that data table?
Mamta Dalal
Currently I am binding the datatable to the datagridview. I am not so sure what you mean by binding to the that datatable.
Chinjoo
+1  A: 

The built-in WinForms DGV does not support grouping. Here is an article where someone has added this functionality themselves (note that I have not used this myself and so am not making a recommendation): http://blogs.vbcity.com/hotdog/archive/2008/12/19/9226.aspx

Alternately there are countless third-party DGV controls for sale. Infragistics has an excellent one that I can recommend which does provide grouping: http://www.infragistics.com/dotnet/netadvantage/winforms/wingrid.aspx#Overview

Tergiver