We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Can't merge cells in GridControl of MultiColumnComboBox


We are using a MultiColumnComboBox control and we would like to customize the grid to merge cells (see above screenshot). However, using the below code does not seem to work. The QueryCanMergeCells callback does not appear to even get called.


var grid = this.multiColumnComboBox1.ListBox.Grid; // Grid is SyncFusion.Windows.Forms.Grid.GridControl type

grid.QueryCellInfo += Grid_QueryCellInfo;
            
// Set MergeCells direction for the GridControl.
grid.TableStyle.MergeCell = GridMergeCellDirection.ColumnsInRow; // | GridMergeCellDirection.RowsInColumn;

// Set merge cells behavior for the Grid.
grid.Model.Options.MergeCellsMode = GridMergeCellsMode.OnDemandCalculation | GridMergeCellsMode.MergeColumnsInRow;
            
grid.Model.Options.MergeCellsLayout = GridMergeCellsLayout.Grid;

grid.QueryCanMergeCells += new GridQueryCanMergeCellsEventHandler(Grid_QueryCanMergeCells);


private void Grid_QueryCanMergeCells(object sender, GridQueryCanMergeCellsEventArgs e)
{
     // Checking whether it is already merged cells.
     if (!e.Result)
     {
          // Sets merging for two cells with different data.
          var cell1 = e.Style1.CellIdentity;
          var cell2 = e.Style2.CellIdentity;
          if (cell1.RowIndex == 1 && 1 == cell2.RowIndex && cell1.ColIndex == 1 & cell2.ColIndex == 2)
         {
                    e.Result = true;
                    e.Handled = true;
                    e.Style1.CellValue = "test";
         }
     }
}

Attached the sample solution for reference. Thank you in advance.

Attachment: SyncFusionDemo_f97e7981.zip

3 Replies

AR Arulpriya Ramalingam Syncfusion Team July 19, 2019 12:52 PM UTC

Hi Peregrino, 
 
Thanks for using Syncfusion products. 
 
We have analyzed the provided sample and in which the MergeCell option of the cells were not updated for the each cells. In order to overcome this scenario, the QueryCellInfo event can be used to set the MergeCell style for each cells. We have modified the provided sample and please make use of the below code and sample, 
 
Code example 
 
private void Grid_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e) 
{ 
    //To set the merge cell for each cell. 
    e.Style.MergeCell = GridMergeCellDirection.ColumnsInRow; 
    if (e.ColIndex == 1 && e.RowIndex > 1) 
    { 
        //To change the cell type as CheckBox 
        e.Style.CheckBoxOptions = new GridCheckBoxCellInfo("true", "false", "", true); 
        e.Style.CellType = GridCellTypeName.CheckBox; 
    } 
} 
 

Regards, 
Arulpriya 



PE Peregrino July 19, 2019 04:31 PM UTC

That worked. Thank you so much, Arulpriya!


JP Jagadeesan Pichaimuthu Syncfusion Team July 22, 2019 06:37 AM UTC

Hi Peregrino, 
 
Thanks for the update. 
 
We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you. 
 
Regards, 
Jagadeesan 


Loader.
Up arrow icon