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 property of the C1DisplayColumn 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 on the Country field.
If data-sensitive cell merging is enabled for the Country column at run time, then its cells are grouped according to their contents:
Me.C1TrueDBGrid1.Splits(0).DisplayColumns("Country").Merge = C1.Win.C1TrueDBGrid.ColumnMergeEnum.Free
· C#
this.c1TrueDBGrid1.Splits(0).DisplayColumns("Country").Merge = C1.Win.C1TrueDBGrid.ColumnMergeEnum.Free;
· Delphi
Self.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 property. The behavior of the marquee in other columns is not affected, however.
If a design-time layout is specified, the same effect can be achieved by setting the Merge property of the desired C1DisplayColumn 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.
Me.C1TrueDBGrid1.Splits(0).DisplayColumns(0).Merge = C1.Win.C1TrueDBGrid.ColumnMergeEnum.None
Me.C1TrueDBGrid1.Splits(0).DisplayColumns(1).Merge = C1.Win.C1TrueDBGrid.ColumnMergeEnum.None
Me.C1TrueDBGrid1.Splits(0).DisplayColumns(2).Merge = C1.Win.C1TrueDBGrid.ColumnMergeEnum.None
Me.C1TrueDBGrid1.Splits(0).DisplayColumns(3).Merge = C1.Win.C1TrueDBGrid.ColumnMergeEnum.None
· C#
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
· Delphi
Self.C1TrueDBGrid1.Splits(0).DisplayColumns(0).Merge := C1.Win.C1TrueDBGrid.ColumnMergeEnum.None;
Self.C1TrueDBGrid1.Splits(0).DisplayColumns(1).Merge := C1.Win.C1TrueDBGrid.ColumnMergeEnum.None;
Self.C1TrueDBGrid1.Splits(0).DisplayColumns(2).Merge := C1.Win.C1TrueDBGrid.ColumnMergeEnum.None;
Self.C1TrueDBGrid1.Splits(0).DisplayColumns(3).Merge := C1.Win.C1TrueDBGrid.ColumnMergeEnum.None;
Free Merge
Free merge combines like values in adjacent rows.
Notice how the first Region cell (East) merges across employees (Donna and John) to its left.
' Set free merging.
Me.C1TrueDBGrid1.Splits(0).DisplayColumns(0).Merge = C1.Win.C1TrueDBGrid.ColumnMergeEnum.Free
Me.C1TrueDBGrid1.Splits(0).DisplayColumns(1).Merge = C1.Win.C1TrueDBGrid.ColumnMergeEnum.Free
Me.C1TrueDBGrid1.Splits(0).DisplayColumns(2).Merge = C1.Win.C1TrueDBGrid.ColumnMergeEnum.Free
Me.C1TrueDBGrid1.Splits(0).DisplayColumns(3).Merge = C1.Win.C1TrueDBGrid.ColumnMergeEnum.Free
' Set each column's vertical alignment to Center.
Me.C1TrueDBGrid1.Splits(0).DisplayColumns(0).Style.VerticalAlignment = C1.Win.C1TrueDBGrid.AlignVertEnum.Center
Me.C1TrueDBGrid1.Splits(0).DisplayColumns(1).Style.VerticalAlignment = C1.Win.C1TrueDBGrid.AlignVertEnum.Center
Me.C1TrueDBGrid1.Splits(0).DisplayColumns(2).Style.VerticalAlignment = C1.Win.C1TrueDBGrid.AlignVertEnum.Center
Me.C1TrueDBGrid1.Splits(0).DisplayColumns(3).Style.VerticalAlignment = C1.Win.C1TrueDBGrid.AlignVertEnum.Center
· C#
// 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;
· Delphi
// Set free merging.
Self.C1TrueDBGrid1.Splits(0).DisplayColumns(0).Merge := C1.Win.C1TrueDBGrid.ColumnMergeEnum.Free;
Self.C1TrueDBGrid1.Splits(0).DisplayColumns(1).Merge := C1.Win.C1TrueDBGrid.ColumnMergeEnum.Free;
Self.C1TrueDBGrid1.Splits(0).DisplayColumns(2).Merge := C1.Win.C1TrueDBGrid.ColumnMergeEnum.Free;
Self.C1TrueDBGrid1.Splits(0).DisplayColumns(3).Merge := C1.Win.C1TrueDBGrid.ColumnMergeEnum.Free;
// Set each column's vertical alignment to Center.
Self.C1TrueDBGrid1.Splits(0).DisplayColumns(0).Style.VerticalAlignment := C1.Win.C1TrueDBGrid.AlignVertEnum.Center;
Self.C1TrueDBGrid1.Splits(0).DisplayColumns(1).Style.VerticalAlignment := C1.Win.C1TrueDBGrid.AlignVertEnum.Center;
Self.C1TrueDBGrid1.Splits(0).DisplayColumns(2).Style.VerticalAlignment := C1.Win.C1TrueDBGrid.AlignVertEnum.Center;
Self.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.
Notice how the first Region cell (East) no longer merges across employees to its left.
' Set restricted merging.
Me.C1TrueDBGrid1.Splits(0).DisplayColumns(0).Merge = C1.Win.C1TrueDBGrid.ColumnMergeEnum.Restricted
Me.C1TrueDBGrid1.Splits(0).DisplayColumns(1).Merge = C1.Win.C1TrueDBGrid.ColumnMergeEnum.Restricted
Me.C1TrueDBGrid1.Splits(0).DisplayColumns(2).Merge = C1.Win.C1TrueDBGrid.ColumnMergeEnum.Restricted
Me.C1TrueDBGrid1.Splits(0).DisplayColumns(3).Merge = C1.Win.C1TrueDBGrid.ColumnMergeEnum.None
' Set each column's veritcal alignment to Center.
Me.C1TrueDBGrid1.Splits(0).DisplayColumns(0).Style.VerticalAlignment = C1.Win.C1TrueDBGrid.AlignVertEnum.Center
Me.C1TrueDBGrid1.Splits(0).DisplayColumns(1).Style.VerticalAlignment = C1.Win.C1TrueDBGrid.AlignVertEnum.Center
Me.C1TrueDBGrid1.Splits(0).DisplayColumns(2).Style.VerticalAlignment = C1.Win.C1TrueDBGrid.AlignVertEnum.Center
Me.C1TrueDBGrid1.Splits(0).DisplayColumns(3).Style.VerticalAlignment = C1.Win.C1TrueDBGrid.AlignVertEnum.Center
· C#
// 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 veritcal 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;
· Delphi
// Set restriced merging.
C1TrueDBGrid1.Splits(0).DisplayColumns(0).Merge := C1.Win.C1TrueDBGrid.ColumnMergeEnum.Restricted;
C1TrueDBGrid1.Splits(0).DisplayColumns(1).Merge := C1.Win.C1TrueDBGrid.ColumnMergeEnum.Restricted;
C1TrueDBGrid1.Splits(0).DisplayColumns(2).Merge := C1.Win.C1TrueDBGrid.ColumnMergeEnum.Restricted;
C1TrueDBGrid1.Splits(0).DisplayColumns(3).Merge := C1.Win.C1TrueDBGrid.ColumnMergeEnum.None;
// Set each column's vertical alignment to Center.
C1TrueDBGrid1.Splits(0).DisplayColumns(0).Style.VerticalAlignment := C1.Win.C1TrueDBGrid.AlignVertEnum.Center;
C1TrueDBGrid1.Splits(0).DisplayColumns(1).Style.VerticalAlignment := C1.Win.C1TrueDBGrid.AlignVertEnum.Center;
C1TrueDBGrid1.Splits(0).DisplayColumns(2).Style.VerticalAlignment := C1.Win.C1TrueDBGrid.AlignVertEnum.Center;
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 the new row is added to the underlying database, then its data will also be uneditable within the merged column(s).
Note: Merged cells are not limited to displaying text. Display bitmaps within merged cells by populating the ValueItems object as described earlier in Specifying Text-to-Picture Translations. The section Applying Pictures to Grid Elements describes a more flexible method for displaying in-cell graphics using Style objects.
Send comments about this topic to ComponentOne. Copyright © ComponentOne LLC. All rights reserved. |