CGrid:SetCol


The SetCol method stores an array of values to a grid column.

Syntax

bSuccess = G:SetCol( array, nCol )

bSuccess = G:SetCol( array, nCol, nRows )

bSuccess = G:SetCol( array, nCol, nRowMin, nRowMax )

where

    array is a Lua array containing the data.

    nCol is the column index. Data is stored in all rows in the column.

    nRows is the number of rows to set. The array data are stored starting at row 1. The row range is clipped to the range [1, GetNumRows].

    nRowMin, nRowMax are the indices of the beginning and ending grid rows. The row range is clipped to the range [1, GetNumRows].

    bSuccess is the returned success code. On success it is true, otherwise false.

Examples

The following script creates a grid and stores numbers in columns 1 through 5 and rows 1 through 3. The script retrieves data from column 2, row 2:

G = NewGrid(10,4)

-- new grid with 3 cols, 10 rows, 1 Sheet

G:SetRow( {2,3,4,5,6}, 1 )

-- set 5 columns in row 1

G:SetRow( {4,5,6,7,8}, 2 )

-- set 5 columns in row 2

G:SetRow( {5,6,7,8,9}, 3 )

-- set 5 columns in row 3

c = 2 ; r = 2

-- specify column 2, row 2

Printf("Cell[%d][%d] = G:Get(c,r) )

-- result: Cell[2][2] = 5

t = { 100, 101, 102 }

-- setup a table of data

G:SetCol( t, c )

-- set data in column c (= 2)

Printf("Cell[%d][%d] = G:Get(c,r) )

-- result: Cell[2][2] = 101

The following script creates a grid like the one above. The script sets data in column 1, rows 2 through 3:

G = NewGrid(10,4)

-- new grid with 3 cols, 10 rows, 1 Sheet

G:SetRow( {2,3,4,5,6}, 1 )

-- set 5 columns in row 1

G:SetRow( {4,5,6,7,8}, 2 )

-- set 5 columns in row 2

G:SetRow( {5,6,7,8,9}, 3 )

-- set 5 columns in row 3

c = 1 ; rMin = 2 ; rMax = 3

-- specify column 1 and rows

Printf("Cell[%d][%d] = G:Get(c,rMin) )

-- result: Cell[2][2] = 4

t = { 100, 101, 102 }

-- setup a table of data

G:SetCol( t, c, rMin, rMax )

-- set data in column c (= 1)

Printf("Cell[%d][%d] = G:Get(c,rMin) )

-- result: Cell[2][2] = 100

Related Topics

SetRow

GetCol

CGrid class