Connecting Tech Pros Worldwide Help | Site Map

DataGridView Merge Cells

Newbie
 
Join Date: Jul 2009
Posts: 14
#1: Oct 1 '09
Hi All,

I'm looking for a way to merge cells by their content in DataGridView.

For Ex'

sgphoto_2009_10_01-02_34_16.png

How can I implement this table using DataGridView ?

The table is dynamic so it must be a code base.

Thanks For the help.
Familiar Sight
 
Join Date: Jul 2009
Location: Calgary, Alberta, Canada
Posts: 211
#2: Oct 1 '09

re: DataGridView Merge Cells


You had a similar thread before, right? Though I guess they are slightly different...
How to merge items in table (by relation)
... did you ever find a solution to that one? I remember googling around but couldn't find anything helpful for you.

For this one, I think you're in the same boat... you'll have to do this manually. I'd recommend parsing through the DataTable's rows and then moving things into a new DataTable (the merged one). If the row's left column already exists in the merge DataTable, do nothing (or figure out what to do when the values differ). If it does not exist, add it in.

Good luck!
Expert
 
Join Date: Jun 2008
Location: Pretoria, South Africa
Posts: 410
#3: Oct 1 '09

re: DataGridView Merge Cells


If your data is stored in a DB you can get the data in the desired format by incorporating the distinct keyword into your select statement.
Newbie
 
Join Date: Jul 2009
Posts: 14
#4: Oct 1 '09

re: DataGridView Merge Cells


Hi ALL,

Thanks for the replay.

I'm giving up on this one, I will use the distinct keyword (thanks cloud255) and in a new table below the main one I will display the rest of the data.
Familiar Sight
 
Join Date: Jul 2009
Location: Calgary, Alberta, Canada
Posts: 211
#5: Oct 1 '09

re: DataGridView Merge Cells


Quote:

Originally Posted by cloud255 View Post

If your data is stored in a DB you can get the data in the desired format by incorporating the distinct keyword into your select statement.

Oh good god, that's way better! The select statement... of course, it's so simple!

Nice one :) Can you tell I'm in data manipulation mode? Bah...
Expert
 
Join Date: Jun 2008
Location: Pretoria, South Africa
Posts: 410
#6: Oct 1 '09

re: DataGridView Merge Cells


Quote:

Originally Posted by GaryTexmo View Post

Oh good god, that's way better! The select statement... of course, it's so simple!

Nice one :) Can you tell I'm in data manipulation mode? Bah...

You can do this in Linq too, that will allow you to manipulate the data in memory in C#, which would be better if the data was in an XML file or something else that doesn't support SQL.

But Linq's syntax can take a while to get used too and the performance impact of Linq is not worth it when SQL can produce the same results by adding a single keyword.
Reply