Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
435
Merging cells based on other columns
posted

Hi

I'm using the mergecell function of the WinGrid to merge cells in a single column where they have the same value, and it works great. However, I sometimes need to only merge cells based on the value of another column e.g. I have a table with three columns. I am merging the third column values across rows if they have the same value. However, I only want the merge to happen when the value in the first column also matches e.g.

Column A    Column B    Column C
Pencils        Apples        1
Pencils        Pears        1
---------------------------------
Pens        Bananas        1
Pens        Pineapples    1
---------------------------------
Pens        Grapefruit    2

In the example above, the merge is occuring on Column C. Currently, the first four rows all get merged together, but I would like the merge to only occur on what is effectively the compound key of Columns A and C - so the first two rows should be merged, three and four should be merged, and the fifth should be on its own.

Can this be accomplished in the Grid?

Parents
No Data
Reply
  • 469350
    Offline posted

     Hi,

        Yes, I beleive you can do this using the MergedCellEvaluator property on the column. What you do is create a class that implements IMergedCellEvaluator. This interface has only one method: ShouldCellsBeMerged. The method passes in two rows and the column being merged and you return true or false to indicate whether or not to merge the cells. 

Children