DataGridView Merge Cells

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • liadmz
    New Member
    • Jul 2009
    • 32

    DataGridView Merge Cells

    Hi All,

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

    For Ex'

    Click image for larger version

Name:	SGPhoto_2009_10_01 02_34_16.png
Views:	1
Size:	4.2 KB
ID:	5415701

    How can I implement this table using DataGridView ?

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

    Thanks For the help.
  • GaryTexmo
    Recognized Expert Top Contributor
    • Jul 2009
    • 1501

    #2
    You had a similar thread before, right? Though I guess they are slightly different...

    ... 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!

    Comment

    • cloud255
      Recognized Expert Contributor
      • Jun 2008
      • 427

      #3
      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.

      Comment

      • liadmz
        New Member
        • Jul 2009
        • 32

        #4
        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.

        Comment

        • GaryTexmo
          Recognized Expert Top Contributor
          • Jul 2009
          • 1501

          #5
          Originally posted by cloud255
          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...

          Comment

          • cloud255
            Recognized Expert Contributor
            • Jun 2008
            • 427

            #6
            Originally posted by GaryTexmo
            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.

            Comment

            Working...