Articles in this section
Category / Section

How to merge the adjacent cells if they have the same value

1 min read

As a workaround we can achieve the required behavior by hooking QueryCoveredRange event at sample level. Drawing cost will be increased a little as we are merging these at runtime. The following code explains the same.

C#

this.pivotGrid1.InternalGrid.QueryCoveredRange += new GridQueryCoveredRangeEventHandler(InternalGrid_QueryCoveredRange);
//To Merge cells if CellValue is same
void InternalGrid_QueryCoveredRange(object sender, GridQueryCoveredRangeEventArgs e)
{
if (e.CellRowColumnIndex.ColumnIndex > this.pivotGrid1.PivotRows.Count-1 && e.CellRowColumnIndex.RowIndex > this.pivotGrid1.PivotColumns.Count)
{
string cellValue = Convert.ToString(this.pivotGrid1.InternalGrid.Model[e.CellRowColumnIndex.RowIndex, e.CellRowColumnIndex.ColumnIndex].CellValue);
int count = e.CellRowColumnIndex.ColumnIndex + 1;
if (!string.IsNullOrEmpty(cellValue) && count < this.pivotGrid1.InternalGrid.Model.ColumnCount)
{
while (count < this.pivotGrid1.InternalGrid.Model.ColumnCount && cellValue == Convert.ToString(this.pivotGrid1.InternalGrid.Model[e.CellRowColumnIndex.RowIndex, count].CellValue))
{
count++;
}
e.Range = new CoveredCellInfo(e.CellRowColumnIndex.RowIndex, e.CellRowColumnIndex.ColumnIndex, e.CellRowColumnIndex.RowIndex, count);
e.Handled = true;
}
}
}

 

http://www.syncfusion.com/downloads/Support/DirectTrac/94771/clip_image001-725336467.png

Figure: Pivot Grid shows merging of cells

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied