# Merge

## Content



If the underlying grid data is sorted, the readability of the display may be improved by grouping adjacent like-valued cells within the sorted column(s). The [Merge](/componentone/docs/win/online-truedbgrid/) property of the [C1DisplayColumn](/componentone/docs/win/online-truedbgrid/) object controls whether its data cells are grouped in this manner to form a single non-editable cell, using the **ColumnMergeEnum**. By default, this property is set to **None**, and each physical row within a column displays a data value, if any.

Consider the following grid, which is sorted by the _Country_ field.

![](https://cdn.mescius.io/document-site-files/images/a1b176e5-6638-4b1f-a786-e41a817558bb/images/not-merged.png)

If data-sensitive cell merging is enabled for the _Country_ column at run time, then its cells are grouped according to their contents. For example:

```csharp
this.c1TrueDBGrid1.Splits[0].DisplayColumns["Country"].Merge = C1.Win.C1TrueDBGrid.ColumnMergeEnum.Free;                  
```

Executing this statement produces the following display. Note that when the current cell is in the _Country_ column, the marquee spans all like-valued rows and takes on the appearance of a dotted rectangle, regardless of the setting of the [MarqueeStyle](/componentone/docs/win/online-truedbgrid/) property. The behavior of the marquee in other columns is not affected, however.

![](https://cdn.mescius.io/document-site-files/images/a1b176e5-6638-4b1f-a786-e41a817558bb/images/merging-countrywise.png)

If a design-time layout is specified, the same effect can be achieved by setting the Merge property of the desired [C1DisplayColumn](/componentone/docs/win/online-truedbgrid/) object within the **C1DisplayColumn Collection Editor**, which can be accessed by clicking on the **ellipsis** button (...) after the **DisplayColumns** property in the **Split Collection Editor**.

The Merge property can be set to **Free**, which combines like values in adjacent rows, or **Restricted**, which combines like values in adjacent rows in the same row span as the previous column. The difference between **Free** and **Restricted** settings is whether cells within the same contents should always be merged (**Free**) or only when adjacent cells to the left or top are also merged (**Restricted**). The examples below illustrate the difference.

### No Merge (Regular Spreadsheet View)

No merge displays data in a regular spreadsheet view.

![](https://cdn.mescius.io/document-site-files/images/a1b176e5-6638-4b1f-a786-e41a817558bb/images/cell-merging-4.png)

```csharp
this.c1TrueDBGrid1.Splits[0].DisplayColumns[0].Merge = C1.Win.C1TrueDBGrid.ColumnMergeEnum.None;
this.c1TrueDBGrid1.Splits[0].DisplayColumns[1].Merge = C1.Win.C1TrueDBGrid.ColumnMergeEnum.None;
this.c1TrueDBGrid1.Splits[0].DisplayColumns[2].Merge = C1.Win.C1TrueDBGrid.ColumnMergeEnum.None;
this.c1TrueDBGrid1.Splits[0].DisplayColumns[3].Merge = C1.Win.C1TrueDBGrid.ColumnMergeEnum.None                   
```

### Free Merge

Free merge combines like values in adjacent rows.

![](https://cdn.mescius.io/document-site-files/images/a1b176e5-6638-4b1f-a786-e41a817558bb/images/cell-merging-5.png)

Notice how the first _Region_ cell (East) merges across employees (Donna and John) to its left.

```csharp
// Set free merging.
this.c1TrueDBGrid1.Splits[0].DisplayColumns[0].Merge = C1.Win.C1TrueDBGrid.ColumnMergeEnum.Free;
this.c1TrueDBGrid1.Splits[0].DisplayColumns[1].Merge = C1.Win.C1TrueDBGrid.ColumnMergeEnum.Free;
this.c1TrueDBGrid1.Splits[0].DisplayColumns[2].Merge = C1.Win.C1TrueDBGrid.ColumnMergeEnum.Free;
this.c1TrueDBGrid1.Splits[0].DisplayColumns[3].Merge = C1.Win.C1TrueDBGrid.ColumnMergeEnum.Free;
// Set each column's vertical alignment to Center.
this.c1TrueDBGrid1.Splits[0].DisplayColumns[0].Style.VerticalAlignment = C1.Win.C1TrueDBGrid.AlignVertEnum.Center;
this.c1TrueDBGrid1.Splits[0].DisplayColumns[1].Style.VerticalAlignment = C1.Win.C1TrueDBGrid.AlignVertEnum.Center;
this.c1TrueDBGrid1.Splits[0].DisplayColumns[2].Style.VerticalAlignment = C1.Win.C1TrueDBGrid.AlignVertEnum.Center;
this.c1TrueDBGrid1.Splits[0].DisplayColumns[3].Style.VerticalAlignment = C1.Win.C1TrueDBGrid.AlignVertEnum.Center;
```

### Restricted Merge

Restricted merge combines like values in adjacent rows in the same row span as the previous column.

![](https://cdn.mescius.io/document-site-files/images/a1b176e5-6638-4b1f-a786-e41a817558bb/images/cell-merging-6.png)

Notice how the first _Region_ cell (East) no longer merges across employees to its left.

```csharp
// Set restricted merging.
this.c1TrueDBGrid1.Splits[0].DisplayColumns[0].Merge = C1.Win.C1TrueDBGrid.ColumnMergeEnum.Restricted;
this.c1TrueDBGrid1.Splits[0].DisplayColumns[1].Merge = C1.Win.C1TrueDBGrid.ColumnMergeEnum.Restricted;
this.c1TrueDBGrid1.Splits[0].DisplayColumns[2].Merge = C1.Win.C1TrueDBGrid.ColumnMergeEnum.Restricted;
this.c1TrueDBGrid1.Splits[0].DisplayColumns[3].Merge = C1.Win.C1TrueDBGrid.ColumnMergeEnum.None;
// Set each column's vertical alignment to Center.
this.c1TrueDBGrid1.Splits[0].DisplayColumns[0].Style.VerticalAlignment = C1.Win.C1TrueDBGrid.AlignVertEnum.Center;
this.c1TrueDBGrid1.Splits[0].DisplayColumns[1].Style.VerticalAlignment = C1.Win.C1TrueDBGrid.AlignVertEnum.Center;
this.c1TrueDBGrid1.Splits[0].DisplayColumns[2].Style.VerticalAlignment = C1.Win.C1TrueDBGrid.AlignVertEnum.Center;
this.c1TrueDBGrid1.Splits[0].DisplayColumns[3].Style.VerticalAlignment = C1.Win.C1TrueDBGrid.AlignVertEnum.Center;
```

If the Merge property is set to **Free** or **Restricted** for a column, then none of the data cells can be edited, even if all rows contain unique values. The only exception to this is the AddNew row. However, once a new row is added to the underlying database, then its data will also be uneditable within the merged column(s).


> type=note
> **Note**: Merged cells are not limited to displaying text. Display bitmaps within merged cells by populating the [ValueItems](/componentone/docs/win/online-truedbgrid/) object as described earlier in [Specifying Text-to-Picture Translations](/componentone/docs/win/online-truedbgrid/translate#textpicturetranslate). The section **Applying Pictures to Grid Elements** describes a more flexible method for displaying in-cell graphics using [Style](/componentone/docs/win/online-truedbgrid/) objects.

## Formatting Merged Cells

Use the [HorizontalAlignment](/componentone/docs/win/online-truedbgrid/) and [VerticalAlignment](/componentone/docs/win/online-truedbgrid/) properties of the column's [Style](/componentone/docs/win/online-truedbgrid/) object to center the data within the merged cell, as in the following figure.<br />

![](https://cdn.mescius.io/document-site-files/images/a1b176e5-6638-4b1f-a786-e41a817558bb/images/style-merge.png)

In the **Splits Collection Editor**, access these properties by expanding the [Style](/componentone/docs/win/online-truedbgrid/) property node at the same level of the tree as the [Merge](/componentone/docs/win/online-truedbgrid/) property. Or, in code:

```csharp
C1.Win.C1TrueDBGrid.Style s;
s = this.c1TrueDBGrid1.Splits[0].DisplayColumns["Country"].Style;
s.HorizontalAlignment = C1.Win.C1TrueDBGrid.AlignHorzEnum.Center;
s.VerticalAlignment = C1.Win.C1TrueDBGrid.AlignVertEnum.Center;
```