CGrid:SetRow


The SetRow method stores an array of values to a grid row.

Syntax

bSuccess = G:SetRow( array, nRow )

bSuccess = G:SetRow( array, nRow, nCols )

bSuccess = G:SetRow( array, nRow, nColMin, nColMax )

where

    array is a Lua array containing the data.

    nRow is the row index. Data is stored in all columns in the row.

    nCols is the number of columns to set. The array data are stored starting at column 1. The column range is clipped to the range [1, GetNumCols].

    nColMin, nColMax are the indices of the beginning and ending grid columns. The column range is clipped to the range [1, GetNumCols].

    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:SetRow( t, r )

-- set data in row r (= 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 row 2, columns 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

cMin = 2 ; cMax = 3 ; r = 2

-- specify row 1 and columns

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

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

t = { 100, 101, 102 }

-- setup a table of data

G:SetRow( t, r, cMin, cMax )

-- set data in row r (= 2)

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

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

Related Topics

SetCol

GetRow

CGrid class