CGridView:JoinCells


The JoinCells method joins, or "merges", a block of cells into a single cell. Although joining can be done anywhere in the grid, it is commonly used to group columns or rows using a second or other line of headings. For example, a second (upper) heading row may be used to make a different heading for groups of every 3 columns. Note that columns and rows in the table body begin at index 1. Side and top headings have index 0, -1, -2, and so on, with increasing distance from the table body. Joined cells can be returned to their original layout using UnJoinCells.

The column and row location of the joined cells continues to use the indices of unjoined cells. For example, if cells starting at column 1 were joined into groups of 10 columns, then the first joined cell is at column index 1, the second joined cell is column 11, and so on.

Syntax

CGridView:JoinCells( nColLeft, nColRight, nRowTop, nRowBottom )

bullet.gif    where nColLeft, nColRight, nRowTop, and nRowBottom are the boundaries of the group of cells to join.

 

The grid below shows joining in the 2nd header row at index -1. Also notice that the horizontal alignment of joined cells is set to "center".

Example

The following script creates a grid with 2 heading rows and joins the top-most row to cover groups of 3 columns. The heading row closest to the grid body (row index 0) is filled with default column labels (that may be changed using SetStr for columns in row 0). Cells in the second heading row at index -1 are joined into groups of 3 columns each and the labels "A", "B", "C", and "D" are assigned to the 4 joined column headings:

params =

-- define the grid properties

{

 

  nCols = 12,

-- create 12 columns

  nRows = 20,

 

  nSheets = 1,

 

  nSH_Cols = 1,

 

  nSH_Width = 24,

 

  nTH_Rows = 2,

-- create 2 top heading rows

  nTH_Height = 16,

-- each top heading row has a height of 16

}

 

G = new_gridview("My Grid", params )

-- create a new CGridView window

label = { "A", "B", "C", "D" }

-- create some simple labels

nJoinLabel = 1

-- index for accessing join labels

nCols = G:GetNumCols()

-- get the column count

for nCol = 1,nCols,3 do

-- step every 3rd column

  G:JoinCells( nCol, nCol+2, -1, -1)

-- join the 3 columns, from nCol through nCol+2

  G:SetHorzAlign( nCol, -1, 3 )

-- 3 means align center

  G:SetStr(nCol, -1, label[nJoinLabel])

-- set the title of the joined heading cells

  nJoinLabel = nJoinLabel + 1

-- point index to the next label

end

 

Related Topics

CGridView class

UnJoinCells

SetHorzAlign

SetVertAlign


Mira Pro x64 Script User's Guide, Copyright Ⓒ 2023 Mirametrics, Inc. All Rights Reserved.