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
1225
Merge Cell
posted

I have my grid sorted on the the first 4 columns and I would like to merge the cells only within a logical group according to the sort.  An example with help illustrate.

 

Each time the first column changes all of the next columns should not merge and display.

IF the second column changes then all subsequent columns should display

For this data

Symbol Expiration Strike  Put/Call Shares
AAPL 10/22/2010 300 C 10
AAPL 10/22/2010 300 C 10
AAPL 10/22/2010 300 C 3
AAPL 10/22/2010 300 C 45
AAPL 10/22/2010 300 C 56
NFLX 10/22/2010 300 C 8
NFLX 10/22/2010 300 C 3
NFLX 10/22/2010 300 C 96
NFLX 10/22/2010 300 C 45
NFLX 10/22/2010 300 C 67

 

I want it to look like this:

Symbol Expiration Strike  Put/Call Shares
AAPL 10/22/2010 300 C 10
10
3
45
56
NFLX 10/22/2010 300 C 8
3
96
45
67

 

But I get this:

Symbol Expiration Strike  Put/Call Shares
AAPL 10/22/2010 300 C 10
10
3
45
56
NFLX 8
3
96
45
67

  • 5118
    posted

    Hi,

    You can achieve this by implementing a custom merged cell evalutor for the columns you want to alter the merged behavior. 

    To get you started you can create a class that implements the IMergedCellEvaluator interface and assigning it to a column:

    class CustomCellMerger : IMergedCellEvaluator
        {
            public bool ShouldCellsBeMerged(UltraGridRow row1, UltraGridRow row2, UltraGridColumn column)
            {
                if (!row1.Cells["Symbol"].IsMergedWith(row2.Cells["Symbol"]))
                {
                    return false;
                }

                return true;
            }
        }

    Back at the grid set the column to use this evaluator:

    private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
    {
         e.Layout.Bands[0].Columns["Expiration"].MergedCellEvaluator = new CustomCellMerger();
    }

    Continue this out for the other columns you want to modify the merged cell behavior for and you can implement the merging behavior you were after.