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:
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:
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