Conditioning grid cells for data entry

Date:8 February, 2002
Product/Release:Visual LANSA
Abstract:Conditioning grid cells for data entry
Submitted By:LANSA Technical Support
Last Review:November 2010

A common requirement when using a grid for data maintenance, is to limit the pieces of data that can be changed conditionally e.g. a user does not have authority to change certain fields.

This can be achieved very simply using the following technique.

The user can only work on the focus item. Therefore, we can make the appropriate columns in the grid readonly true or false depending on the requirement.

There is no concern with the other entries as they are not the focus item.

The following example shows a list of employees from file PSLMST. If the salary is less than 50,000, the surname and givename can be changed.

Function Options(*DIRECT)
Begin_Com Role(*EXTENDS #PRIM_FORM) Height(422) Layoutmanager(#ATLM_1) Left(306) Top(112) Width(670)
Define_Com Class(#PRIM_ATLM) Name(#ATLM_1)
Define_Com Class(#PRIM_PANL) Name(#PANL_1) Displayposition(1) Left(0) Parent(#COM_OWNER) Tabposition(1) Tabstop(False) Top(345) Width(662)
Define_Com Class(#PRIM_ATLI) Name(#ATLI_1) Attachment(Bottom) Manage(#PANL_1) Parent(#ATLM_1)
Define_Com Class(#PRIM_GRID) Name(#GRID_1) Columnbuttonheight(21) Displayposition(2) Height(345) Left(0) Parent(#COM_OWNER) Showbuttonselection(True) Showselection(True) Showselectionhilight(False) Showsortarrow(True) Tabposition(2) Top(0) Width(662)
Define_Com Class(#PRIM_ATLI) Name(#ATLI_2) Attachment(Center) Manage(#GRID_1) Parent(#ATLM_1)
Define_Com Class(#PRIM_GDCL) Name(#GDCL_1) Displayposition(1) Parent(#GRID_1) Sortonclick(True) Source(#EMPNO) Width(20) Widthtype(Fixed)
Define_Com Class(#PRIM_GDCL) Name(#GDCL_2) Displayposition(2) Parent(#GRID_1) Readonly(False) Sortonclick(True) Source(#SURNAME) Width(28) Widthtype(Fixed)
Define_Com Class(#PRIM_GDCL) Name(#GDCL_3) Displayposition(3) Parent(#GRID_1) Readonly(False) Sortonclick(True) Source(#GIVENAME) Width(31) Widthtype(Fixed)
Define_Com Class(#PRIM_GDCL) Name(#GDCL_4) Columnalign(Right) Displayposition(4) Parent(#GRID_1) Sortonclick(True) Source(#SALARY) Width(20) Widthtype(Fixed)
Def_Cond Name(*SALARY) Cond('#salary *gt 50000')
Evtroutine Handling(#com_owner.CreateInstance)
Set Com(#com_owner) Caption(*component_desc)

* Populate grid
Select Fields(#GRID_1) From_File(PSLMST)
Add_Entry To_List(#GRID_1)
Endselect
Endroutine

Evtroutine Handling(#GRID_1.ItemGotFocus) Options(*NOCLEARMESSAGES *NOCLEARERRORS)
* When focus is set to an item, check the salary value
* If greater than 50,000, no changes to surname or givename
* This could also be writeen with an IF, ELSE
Set Com(#gdcl_2 #gdcl_3) Readonly(*salary)
Endroutine
End_Com