How to reference a particular cell in a Grid and set it to ReadOnly

Date:13 September 2004
Product/Release:Visual LANSA
Abstract:How to set a particular cell in a grid to be Read Only
Submitted By:LANSA Technical Support
Last Review:November 2010

To access the Grid Cell properties and methods, you need to refer to the cell implicitly using:

#GRID_1.cell<[RowNum] [ColNum]>

For example, to set the first cell in a grid to readonly you could use the following line:

SET COM(#GRID_1.CELL<1 1>) READONLY(TRUE)

If you wanted set the current cell to readonly, you could use the following:

SET COM(#GRID_1.cell<#GRID_1.CURRENTITEM.POSITION 1>) READONLY(TRUE)

The example code below allows any cell to be set to Read Only.

FUNCTION OPTIONS(*DIRECT)
BEGIN_COM ROLE(*EXTENDS #PRIM_FORM) CLIENTHEIGHT(327) CLIENTWIDTH(723) HEIGHT(354) LEFT(279) TOP(109) WIDTH(731)
DEFINE_COM CLASS(#PRIM_GRID) NAME(#GRID_1) CAPTIONNOBLANKLINES(True) COLUMNBUTTONHEIGHT(38) COMPONENTVERSION(1) DISPLAYPOSITION(1) HEIGHT(265) LEFT(0) PARENT(#COM_OWNER) SHOWBUTTONSELECTION(True) SHOWSELECTION(True) SHOWSELECTIONHILIGHT(False) SHOWSORTARROW(True) TABPOSITION(1) TOP(0) WIDTH(721)
DEFINE_COM CLASS(#PRIM_STBR) NAME(#STBR_1) DISPLAYPOSITION(2) HEIGHT(24) LEFT(0) MESSAGEPOSITION(1) PARENT(#COM_OWNER) TABPOSITION(2) TABSTOP(False) TOP(303) WIDTH(723)
DEFINE_COM CLASS(#PRIM_PHBN) NAME(#PHBN_1) BUTTONDEFAULT(True) CAPTION('Set Selected Cell to ReadOnly') DISPLAYPOSITION(3) LEFT(0) PARENT(#COM_OWNER) TABPOSITION(3) TOP(272) WIDTH(193)
DEFINE_COM CLASS(#PRIM_GDCL) NAME(#GDCL_1) PARENT(#GRID_1) READONLY(False) SOURCE(#EMPNO) VISIBLE(False) WIDTH(20)
DEFINE_COM CLASS(#PRIM_GDCL) NAME(#GDCL_2) DISPLAYPOSITION(1) PARENT(#GRID_1) READONLY(False) SOURCE(#SURNAME) WIDTH(20)
DEFINE_COM CLASS(#PRIM_GDCL) NAME(#GDCL_3) DISPLAYPOSITION(2) PARENT(#GRID_1) READONLY(False) SOURCE(#GIVENAME) WIDTH(20)
DEFINE_COM CLASS(#PRIM_GDCL) NAME(#GDCL_4) DISPLAYPOSITION(3) PARENT(#GRID_1) READONLY(False) SOURCE(#ADDRESS1) WIDTH(20)
DEFINE_COM CLASS(#PRIM_GDCL) NAME(#GDCL_5) DISPLAYPOSITION(4) PARENT(#GRID_1) READONLY(False) SOURCE(#ADDRESS2) WIDTH(20)
DEFINE_COM CLASS(#PRIM_GDCL) NAME(#GDCL_6) DISPLAYPOSITION(5) PARENT(#GRID_1) READONLY(False) SOURCE(#ADDRESS3) WIDTH(20)
DEFINE_COM CLASS(#PRIM_GDCL) NAME(#GDCL_7) DISPLAYPOSITION(6) PARENT(#GRID_1) READONLY(False) SOURCE(#POSTCODE) WIDTH(20)
DEFINE_COM CLASS(#PRIM_GDCL) NAME(#GDCL_8) DISPLAYPOSITION(7) PARENT(#GRID_1) READONLY(False) SOURCE(#PHONEHME) WIDTH(20)
DEFINE_COM CLASS(#PRIM_GDCL) NAME(#GDCL_9) DISPLAYPOSITION(8) PARENT(#GRID_1) READONLY(False) SOURCE(#PHONEBUS) WIDTH(20)
DEFINE_COM CLASS(#PRIM_GDCL) NAME(#GDCL_10) DISPLAYPOSITION(9) PARENT(#GRID_1) READONLY(False) SOURCE(#STARTDTER) WIDTH(20)
DEFINE_COM CLASS(#PRIM_PHBN) NAME(#PHBN_2) CAPTION('Set Selected Row to ReadOnly') DISPLAYPOSITION(4) LEFT(200) PARENT(#COM_OWNER) TABPOSITION(4) TOP(272) WIDTH(193)
DEFINE_COM CLASS(#PRIM_PHBN) NAME(#PHBN_3) CAPTION('Allow editing') DISPLAYPOSITION(5) LEFT(400) PARENT(#COM_OWNER) TABPOSITION(5) TOP(272) WIDTH(193)
DEFINE_COM CLASS(#prim_var) NAME(#colnm)

EVTROUTINE handling(#com_owner.Initialize)
SET #com_owner caption(*component_desc)
select #grid_1 pslmst
add_Entry #grid_1
endselect
ENDROUTINE

EVTROUTINE HANDLING(#PHBN_1.Click)
SET com(#grid_1.focuscell) readonly(true)
ENDROUTINE
EVTROUTINE HANDLING(#PHBN_2.Click)
For Each(#Current) In(#Grid_1.Columns)
change #std_num #current.displayposition
if '#std_num *gt 0'
SET COM(#GRID_1.cell<#GRID_1.CURRENTITEM.POSITION #std_num>) READONLY(TRUE)
endif
endfor
ENDROUTINE

EVTROUTINE HANDLING(#PHBN_3.Click)
For Each(#Current) In(#Grid_1.Columns)
change #std_num #current.displayposition
if '#std_num *gt 0'
SET COM(#GRID_1.cell<#GRID_1.CURRENTITEM.POSITION #std_num>) READONLY(FALSE)
endif
endfor
ENDROUTINE
END_COM