Version

Merging Cells with the Same Values

Note
Note

This topic demonstrates how to merge cells in the same column. Merging cells in the same row is not supported.

To merge cells that have the same values in a column:

  1. Before you start writing any code, you should place using/imports directives in your code-behind so you don’t need to always type out a member’s fully qualified name.

In Visual Basic:

Imports Infragistics.Win.UltraWinGrid

In C#:

using Infragistics.Win.UltraWinGrid;
  1. Set the MergedCellStyle property of the column object to either Always or OnlyWhenSorted. OnlyWhenSorted setting merges cells of a column only when that column is sorted.

In Visual Basic:

Me.UltraGrid1.DisplayLayout.Bands(0).Columns(3).MergedCellStyle = MergedCellStyle.Always

In C#:

this.ultraGrid1.DisplayLayout.Bands[0].Columns[3].MergedCellStyle = MergedCellStyle.Always;
  1. You can also merge cells in all the columns of an WinGrid™ by using the MergedCellStyle property of the Override object. This eliminates having to set the MergedCellStyle on all the columns.

In Visual Basic:

Me.UltraGrid1.DisplayLayout.Override.MergedCellStyle = MergedCellStyle.Always

In C#:

this.ultraGrid1.DisplayLayout.Override.MergedCellStyle = MergedCellStyle.Always;
  1. You can set the appearance of merged cells by using the MergedCellAppearance property of the Override and the UltraGridColumn objects. Override’s MergedCellAppearance affects all the columns whereas the column’s MergedCellAppearance affects only the associated column.

In Visual Basic:

Me.UltraGrid1.DisplayLayout.Override.MergedCellAppearance.BackColor = Color.LightYellow

In C#:

this.ultraGrid1.DisplayLayout.Override.MergedCellAppearance.BackColor = Color.LightYellow;
  1. The MergedCellEvaluator property can be used for specifying custom logic for determining which cells should merge. The IMergedCellEvaluator interface should be implemented to specify the custom logic for merging cells. For more information on this please see the Use Custom Merge Cell Logic topic.

  2. The MergedCellEvaluationType property of the UltraGridColumn object dictates whether cells are merged based on the cell values or the cell display text. Under certain circumstances cells with different values can display the same text. This can occur for example when a ValueList has been set on the column that maps two values to the same display text, or when some formatting has been applied to the column that rounds numbers off so that two different numbers end up with the same display text. In these situations you may want to merge cells based on the display text rather than the cell values. You can set the MergedCellEvaluationType property to MergeSameText to accomplish this.

In Visual Basic:

Me.UltraGrid1.DisplayLayout.Bands(0).Columns(0).MergedCellEvaluationType = _
  MergedCellEvaluationType.MergeSameText

In C#:

this.ultraGrid1.DisplayLayout.Bands[0].Columns[0].MergedCellEvaluationType =
  MergedCellEvaluationType.MergeSameText;
  1. The following snapshot shows merged cells in Country, City, and Region columns.

merge cells with the same values in ultragrid