Spread Windows Forms 6.0 Product Documentation
Allowing Cells to Merge Automatically
Support Options
Spread Windows Forms 6.0 Product Documentation > Developer's Guide > Customizing Row, Column, and Cell Appearance > Customizing the Appearance of a Cell > Allowing Cells to Merge Automatically

Glossary Item Box

You can have Spread automatically merge cells between columns or between rows if the cells have the same value based on the policy that you set. The component can automatically combine cells that have the same contents. You might want to do this, for example, when bound to a database, as shown in the figure below where the cells in the Year column merge where the year value is the same, as with 1995 and 2003.

Spreadsheet with Merged Cells

Unlike spanning cells, merging is an automatic feature. You tell the component which columns and rows allow cells to be combined automatically, and any cells within that set that have the same contents are combined for you.

For more information on spanning cells, refer to Creating a Span of Cells.

If the merge policy is set to None, cells within a row or column are not merged.

If the merge policy is set to Always, cells within a row or column are merged when the cells have the same values.

If the merge policy is set to Restricted, cells within a row or column are merged when the cells have the same values and the corresponding cells in the previous row or column also have the same value. For example, suppose cells A1:A8 contain {a; a; b; b; b; b; c; c} and cells B1:B8 contain {1; 1; 1; 1; 2; 2; 2; 2}. If column B's merge policy is Always, the cells in column B are merged into two blocks B1:B4 and B5:B8. If column B's merge policy is Restricted then the cells in column B are merged into four blocks B1:B2, B3:B4, B5:B6, and B7:B8.

You can have the cells in the specified row or column combine the cells automatically, or only combine them if the cells to their left (in columns) or above them (in rows) are merged. Typically, if you set the merge policy on several adjacent rows or columns, then you would use Always on the first row or column and Restricted on the remaining rows or columns.

Merged cells take on the properties of the top-left merged cell. For example, if the top-left merged cell has a blue background color, the cells that merge with it display the same background color.

Merged cells do not lose their data; it is simply hidden by the merge. If you remove the merge, the data appears in each cell that was in the merge. You can edit a cell that is merged with another cell. When you double-click the cell to turn edit mode on, the contents of the cell appear in the cell for you to edit them. When you leave edit mode, if the contents of the cell are no longer identical to the cell or cells with which it was previously merged, the cells are no longer displayed as merged.

Cells that are different cell types but have the same contents can merge. For example, a date cell might contain the contents "01/31/02" and the adjacent edit cell might contain the same contents; if the column containing the cells is set to merge, the cells will merge. If the contents change or the merge is removed, the cells maintain their cell types as well as their data.

To set cells to be merged if they have the same value, use the following members:

For more information on these members, refer to the SheetView class (or the Row or Column class) or the DefaultSheetAxisModel of the FarPoint.Win.Spread.Model namespace.

Return to Customizing the Appearance of a Cell.

Using a Shortcut

Use the SetColumMerge or SetRowMerge method for the Sheets or ActiveSheet shortcut object.

Example

This example code sets the row and column merge policies for all rows and all columns.

C# Copy Code
fpSpread1.Sheets[0].SetRowMerge(-1, FarPoint.Win.Spread.Model.MergePolicy.Always);
 
fpSpread1.Sheets[0].SetColumnMerge(-1, FarPoint.Win.Spread.Model.MergePolicy.Always);
 
VB Copy Code
FpSpread1.Sheets(0).SetRowMerge(-1, FarPoint.Win.Spread.Model.MergePolicy.Always)
 
FpSpread1.Sheets(0).SetColumnMerge(-1, FarPoint.Win.Spread.Model.MergePolicy.Always)
 

Using Code

Set the SetColumMerge or SetRowMergemethod for a SheetView object.

Example

This example code sets the first sheet to have 10 columns and 100 rows.

C# Copy Code
FarPoint.Win.Spread.SheetView Sheet0;
 
Sheet0 = fpSpread1.Sheets[0];
 
Sheet0.SetRowMerge(-1, FarPoint.Win.Spread.Model.MergePolicy.Always);
 
Sheet0.SetColumnMerge(-1, FarPoint.Win.Spread.Model.MergePolicy.Always);
 
VB Copy Code
Dim Sheet0 As FarPoint.Win.Spread.SheetView
 
Sheet0 = SetRowMerge(-1, FarPoint.Win.Spread.Model.MergePolicy.Always)
 
Sheet0.ColumnCount = 10
 
Sheet0.SetColumnMerge(-1, FarPoint.Win.Spread.Model.MergePolicy.Always)
 

© 2002-2012 ComponentOne, a division of GrapeCity. All Rights Reserved.