I want to merge cells in a specific column

Posted by: munemoto on 21 July 2022, 4:45 pm EST

    • Post Options:
    • Link

    Posted 21 July 2022, 4:45 pm EST

    Hi,

    I created FlexGrid 3*5;

    I want to merge cell in 1st and 2nd column,

    but cells in 3rd column don’t.

    Is there a way?

  • Posted 25 July 2022, 4:27 am EST

    Hi Tugu,

    I apologize for the delay.

    You can implement this requirement by using setting FlexGrid’s AllowMerging property to Cells as follows:

    
    flexGrid.AllowMerging = C1.WinUI.Grid.GridAllowMerging.Cells;
    
    

    And then for enabling/disabling merging on columns you need to set the GridColumn’s AllowMerging property to true/false as per your requirement as follows:

    
    flexGrid.Columns[0].AllowMerging = true;
    flexGrid.Columns[1].AllowMerging = true;
    flexGrid.Columns[2].AllowMerging = false;
    
    

    I hope it helps :slight_smile:

    Best Regards,

    Kartik

  • Posted 25 July 2022, 5:46 pm EST

    Thanks.

    I 'll try it :slight_smile:

  • Posted 31 July 2022, 5:38 pm EST

    Hello.

    I was able to AutoMerge using this method. Thanks.

    So,

    Can I merge only within the same column and not merge cells side by side?

  • Posted 31 July 2022, 8:14 pm EST

    Hello Dolan,

    The merging works both vertically and horizontally and it depends on your data.

    By default, the cells get merged within the column and after that, if the adjacent rows are the same then it merges them also.

    Please go through the CustomMerging project of the FlexGridExplorer product sample implementing the same.

    …\Documents\ComponentOne Samples\WinUI\CS\Grid\FlexGridExplorer

    If you have any specific use case then please share the screenshot explaining your requirement.

    Regards,

    Prabhat Sharma.

  • Posted 31 July 2022, 10:48 pm EST - Updated 29 September 2022, 1:12 am EST

    Hi Prabhat

    Thank you for your reply.

    if the adjacent rows are the same then it merges them also.

    I do not want this behavior in your description.

    (Yellow cells in the attached image do not need merging)

    Regards,

  • Posted 1 August 2022, 3:42 pm EST

    Hello Dolan,

    We are discussing this with the developers and will get back to you with the updates soon.

    [Internal Tracking ID: C1XAML-30030]

    Regards,

    Prabhat Sharma.

  • Posted 1 August 2022, 5:06 pm EST

    Hi Prabhat

    Understood.

    Currently I work around it by inserting a column with Width=“0” AllowMerging=“False”.

  • Posted 2 August 2022, 3:07 am EST

    Hello,

    For your requirement, you need to generate the custom MergerManager as given in the code snippet below and assign it to your grid:

     private class VerticalMergeManager : GridMergeManager
            {
                public override GridCellRange GetMergedRange(GridCellType cellType, GridCellRange range)
                {
                    if (cellType == GridCellType.Cell)
                    {
                        if (Grid.EditorRange != null && Grid.EditorRange.Contains(range))
                        {
                            return Grid.EditorRange;
                        }
                        if (AllowMerging == GridAllowMerging.Cells || AllowMerging == GridAllowMerging.All)
                            return GetMergedRange(Grid.Cells, new GridCellRange(0, 0, Grid.Cells.Rows.Count - 1, Grid.Cells.Columns.Count - 1), range, true, false);
                    }
                    return base.GetMergedRange(cellType, range);
                }
            }
    
    grid.MergeManager = new VerticalMergeManager();
    

    Please see if it helps!!

    Regards,

    Prabhat Sharma.

  • Posted 7 August 2022, 6:47 pm EST

    Hello,

    I’m a little late to try it, but…

    I was able to get the desired operation.

    Thank you very much.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels