MultiRow allows automatic merging of cells. Cells are merged when the cell values placed in the row are the same in vertically, adjacent rows. This helps reduce visual clutter and makes the data easier to understand.

You can merge text in MultiRow with code or by specifying merging at design time.

Setting Merging at Design Time

Create a template first. You can use the MultiRow task icon to add or edit a template.

Task dialog


Edit your template using the Edit Template option. Select a cell and set the Mergeable property to True. Make sure the cell top is the same as the row top (Location property, Y setting). Also make sure the cell bottom is the same as the row bottom (y+height).

The following image displays a row in the template editor and the settings for the Location and Size properties.

Row properties


The following image displays a cell in the template editor and the settings for the Location and Size properties.

Cell properties


The following image illustrates merging.

Example


Using Code to Merge Cells

This example merges the cells in the first column by setting the Mergeable property to True for the text box cell.

Merged cells


C#
GrapeCity.Win.MultiRow.TextBoxCell text1 = new GrapeCity.Win.MultiRow.TextBoxCell();
text1.Mergeable = true;
GrapeCity.Win.MultiRow.CheckBoxCell check2 = new GrapeCity.Win.MultiRow.CheckBoxCell();
GrapeCity.Win.MultiRow.Template template1 = GrapeCity.Win.MultiRow.Template.CreateGridTemplate(new GrapeCity.Win.MultiRow.Cell[] {text1, check2}, 160, GrapeCity.Win.MultiRow.AutoGenerateGridTemplateStyles.ColumnHeader | GrapeCity.Win.MultiRow.AutoGenerateGridTemplateStyles.RowHeaderAutoNumber);
template1.ColumnHeaders[0].Cells[0].Value = "Column1";
gcMultiRow1.Template = template1;
gcMultiRow1.RowCount = 6;
gcMultiRow1[0, 0].Value = 1;
gcMultiRow1[1, 0].Value = 1;
gcMultiRow1[2, 0].Value = 1;
gcMultiRow1[3, 0].Value = 2;
gcMultiRow1[4, 0].Value = 2;
gcMultiRow1[5, 0].Value = 2;
gcMultiRow1.AllowUserToAddRows = false;

VB
Dim text1 As New GrapeCity.Win.MultiRow.TextBoxCell()
text1.Mergeable = True
Dim check2 As New GrapeCity.Win.MultiRow.CheckBoxCell()
Dim template1 As GrapeCity.Win.MultiRow.Template = GrapeCity.Win.MultiRow.Template.CreateGridTemplate(New GrapeCity.Win.MultiRow.Cell() {text1, check2}, 160, GrapeCity.Win.MultiRow.AutoGenerateGridTemplateStyles.ColumnHeader Or GrapeCity.Win.MultiRow.AutoGenerateGridTemplateStyles.RowHeaderAutoNumber)
template1.ColumnHeaders(0).Cells(0).Value = "Column1"
GcMultiRow1.Template = template1
GcMultiRow1.RowCount = 6
GcMultiRow1(0, 0).Value = 1
GcMultiRow1(1, 0).Value = 1
GcMultiRow1(2, 0).Value = 1
GcMultiRow1(3, 0).Value = 2
GcMultiRow1(4, 0).Value = 2
GcMultiRow1(5, 0).Value = 2
GcMultiRow1.AllowUserToAddRows = False

This example merges cells and displays the new row icon.

C#
GrapeCity.Win.MultiRow.TextBoxCell text1 = new GrapeCity.Win.MultiRow.TextBoxCell();
text1.Mergeable = true;
GrapeCity.Win.MultiRow.CheckBoxCell check2 = new GrapeCity.Win.MultiRow.CheckBoxCell();
GrapeCity.Win.MultiRow.Template template1 = GrapeCity.Win.MultiRow.Template.CreateGridTemplate(new GrapeCity.Win.MultiRow.Cell[] {text1, check2}, 160, GrapeCity.Win.MultiRow.AutoGenerateGridTemplateStyles.ColumnHeader | GrapeCity.Win.MultiRow.AutoGenerateGridTemplateStyles.RowHeaderAutoNumber);
template1.ColumnHeaders[0].Cells[0].Value = "Column1";
gcMultiRow1.Template = template1;
gcMultiRow1.RowCount = 3;
gcMultiRow1[0, 0].Value = 5;
gcMultiRow1[1, 0].Value = 5;
gcMultiRow1[2, 0].Value = 5;

VB
Dim text1 As New GrapeCity.Win.MultiRow.TextBoxCell()
text1.Mergeable = True
Dim check2 As New GrapeCity.Win.MultiRow.CheckBoxCell()
Dim template1 As GrapeCity.Win.MultiRow.Template = GrapeCity.Win.MultiRow.Template.CreateGridTemplate(New GrapeCity.Win.MultiRow.Cell() {text1, check2}, 160, GrapeCity.Win.MultiRow.AutoGenerateGridTemplateStyles.ColumnHeader Or GrapeCity.Win.MultiRow.AutoGenerateGridTemplateStyles.RowHeaderAutoNumber)
template1.ColumnHeaders(0).Cells(0).Value = "Column1"
GcMultiRow1.Template = template1
GcMultiRow1.RowCount = 3
GcMultiRow1(0, 0).Value = 5
GcMultiRow1(1, 0).Value = 5
GcMultiRow1(2, 0).Value = 5

The following conditions must be met for cells to be merged:

  • Cells should be placed in the Row section of the template.

  • The upper and lower ends of the cells in the Row section should be in contact.

  • The Cell.Mergeable property should be set to True.

  • The cell values should not be empty (Is not String.Empty or Null).

  • The Value property of the vertically, adjacent cell should be the same.

  • The cell should be visible.

  • The cell should not be in the detached row (New Row).

  • The cell's top should be equal to the row's top and the cell's bottom should be equal to the row's bottom.


If the MergedCellsSelectionMode property is set to All, all the merged cells are selected. In this case, if you edit the cells, all the merged cells are changed to the same value. If the MergedCellsSelectionMode property is set to Individually, the merged cells are selected one by one. In this case, you can change the value of each cell individually.

When the MergedCellsSelectionMode property is set to All, the behavior is as follows:

  • Even if a merged cell is selected, only one cell is included in the SelectedCells property.

  • Events related to the cell occur for the currently selected cell.

  • If the AllowUserToReverseSelect property is set to True, there are times when the behavior where the selection state of already selected cell(s) is reversed by the Ctrl key + mouse click, and does not work correctly. For example, if cells of the first and second row are merged, after you have selected a cell in the first row using a mouse click, the selection state of the cell is not canceled, even if you press the Ctrl key + mouse click on a cell in the second row.

  • Gradation of the background color is not applied to the merged cells.

  • Top and bottom borders set in the Row section are not applied to the merged cells.

  • When resizing the height of the Row section of the merged cells, it is not possible to resize multiple Row sections together.


If a validator is set in the merged cell, then the validator and the validation action is performed for the top-most cell, but the GcMultiRow.CellValidating event is fired for the current cell; therefore, if you want to use the automatic merge feature, it is recommended that you do not set different validators for the cells.

The QueryCellMergeState event is fired if cells meet the merging conditions. You can use this event to specify the vertical relationship for multiple cells and restrict cell merging if the cell values are different.

The IsMerged method can be used to check whether two cells are merged.

This example uses the IsMerged method.

C#
private void Form1_Load(object sender, EventArgs e)
{
GrapeCity.Win.MultiRow.TextBoxCell text1 = new GrapeCity.Win.MultiRow.TextBoxCell();
GrapeCity.Win.MultiRow.TextBoxCell text2 = new GrapeCity.Win.MultiRow.TextBoxCell();
text1.Name = "text1";
text2.Name = "text2";
text1.Mergeable = true;
text2.Mergeable = true;
text2.Style.Format = "c";
GrapeCity.Win.MultiRow.Template template1 = GrapeCity.Win.MultiRow.Template.CreateGridTemplate(new GrapeCity.Win.MultiRow.Cell[] { text1, text2 }, 160, GrapeCity.Win.MultiRow.AutoGenerateGridTemplateStyles.ColumnHeader | GrapeCity.Win.MultiRow.AutoGenerateGridTemplateStyles.RowHeaderAutoNumber);
template1.ColumnHeaders[0].Cells[0].Value = "Column1";
template1.ColumnHeaders[0].Cells[1].Value = "Column2";
gcMultiRow1.Template = template1;
gcMultiRow1.RowCount = 3;
gcMultiRow1[1, 1].Value = 5;
gcMultiRow1[0, 0].Value = 1;
gcMultiRow1[1, 0].Value = 1;
}

private void button1_Click(object sender, EventArgs e)
{
listBox1.Items.Add(gcMultiRow1.IsMerged(new GrapeCity.Win.MultiRow.CellPosition(0, 0), new GrapeCity.Win.MultiRow.CellPosition(1, 0)).ToString());
}

VB
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load        
Dim text1 As New GrapeCity.Win.MultiRow.TextBoxCell()
Dim text2 As New GrapeCity.Win.MultiRow.TextBoxCell()
text1.Name = "text1"
text2.Name = "text2"
text1.Mergeable = True
text2.Mergeable = True
text2.Style.Format = "c"
Dim template1 As GrapeCity.Win.MultiRow.Template = GrapeCity.Win.MultiRow.Template.CreateGridTemplate(New GrapeCity.Win.MultiRow.Cell() {text1, text2}, 160, GrapeCity.Win.MultiRow.AutoGenerateGridTemplateStyles.ColumnHeader Or GrapeCity.Win.MultiRow.AutoGenerateGridTemplateStyles.RowHeaderAutoNumber)
template1.ColumnHeaders(0).Cells(0).Value = "Column1"
template1.ColumnHeaders(0).Cells(1).Value = "Column2"
GcMultiRow1.Template = template1
GcMultiRow1.RowCount = 3
GcMultiRow1(1, 1).Value = 5
GcMultiRow1(0, 0).Value = 1
GcMultiRow1(1, 0).Value = 1
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
ListBox1.Items.Add(GcMultiRow1.IsMerged(New GrapeCity.Win.MultiRow.CellPosition(0, 0), New GrapeCity.Win.MultiRow.CellPosition(1, 0)).ToString())
End Sub