CGrid:GetRow


The GetRow method returns an array containing the values in a row. The array of row data starts at index 1.

Syntax

array = G:GetRow( nRow )

array = G:GetRow( nRow, nCols )

array = G:GetRow( nRow, nColMin, nColMax )

where

    nRow is the row index. Data is retreived from all columns in the row.

    nCols is the number of columns to retrieve, starting at column 1. The column range is clipped to the range [1, GetNumCols].

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

    array is a Lua array containing the data. On failure, nil is returned.

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 all of row 3:

G = NewGrid(5,5)

-- 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

t = G:GetRow( 3 )

-- fetch data from row 3

for i = 1,#t do

-- do for each row

  Printf("%lg, ", t[i] )

-- result: 5, 6, 7, 8, 9

end

 

The following script creates a grid like the one above. The script retrieves data from row 3 between nColMin=2 and nColMax=400, which is beyond the end of the grid. Notice that the grid starts at index 1 whereas the data start at column nColMin :

G = NewGrid(5,5)

-- 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

nColMin = 2 ; nColMax = 400

-- select columns 2 through 400

t = G:GetRow( 3, nColMin, nColMax )

-- get row 3, starting at column 2

for i = 1,#t do

-- do for each column

  Printf("%lg, ", t[i] )

-- result: 6, 7, 8, 9

end

 

Related Topics

SetRow

GetCol

CGrid class