Draw Cell - GRID SENDMSG() Function 54

Syntax

TF$=SENDMSG(sysgui,id,54,0,grid_information_block${,context{,ERR=lineref}})

Description

For BBj-specific documentation, see Draw Cell - GRID SENDMSG() Function 54 BBj.

This function is the most powerful function to set cell characteristics for one cell and display data in that cell. It works on heading grids as well as main grids.

Parameter

Description

sysgui

SYSGUI channel.

id

Grid control ID.

54

Number of this SENDMSG() function.

0

Always zero.

grid_information_block$

String that contains the grid information block.

Depending on the fields set in the grid_information_block$ parameter, one invocation of the Draw Cell function can do any or all of the following in a cell:

  • Display text in the cell.

  • Set the style to INPUTE, checked or unchecked checkbox, or raised or recessed button.

  • Set the text color.

  • Set the background color.

  • Set the text alignment to centered, left-justified, or right-justified.

  • Display an image.

The power of the function comes from the grid information block, which is a templated string that controls the characteristics of the target cell and the data to be displayed in it. The template for this string follows:

msg:u(4),wparm:u(4),lparm:i(4),col:u(4),row:u(4),textcolor:c(3),backcolor:c(3),
alignment:u(1),style:i(4),imgidx:i(4),x:i(2),y:i(2),
w:u(2),h:u(2),ptx:i(2),pty:i(2),buf:c(1*)

Use the TMPL() function with an index of 1 to retrieve this template. For example:

dim grid_info$:TMPL(sysgui,ind=1)

The relevant fields in the grid information block are described below:

Grid Information Block Field

Description

COL

Column that the target cell is in. Note that column numbering is zero-based.

ROW

Row that the target cell is in. Note that row numbering is zero-based.

TEXTCOLOR

RGB color string for text.

BACKCOLOR

RGB color string for background.

ALIGNMENT

Controls the alignment of text in the cell:

0 = Left alignment

1 = Right alignment

2 = Centered

STYLE

Controls the appearance of the cell. If this function is used on a cell and style is not set, the default appearance of heading and main grid cells is to look like raised buttons. Main grid cells can have their style changed to any of the styles listed below. Heading grid cells can only be changed to look like recessed buttons. Other style settings for heading grids are ignored.

0 = INPUTE control.

1 = Raised button appearance created by shading two sides of the cell.

2 = Recessed button appearance created by shading two sides of the cell.

4 = Checked checkbox, with text, if any, displayed to the right of the checkbox.

8 = Unchecked check box, with text, if any, displayed to the right of the checkbox.

IMGIDX

Index of an imagelist. The imagelist must already be defined, and the grid must have been informed which imagelist to use with a SENDMSG() Function 75.

BUF$

Text to be displayed in cell.

The return value is a one-byte string that indicates the success or failure of an operation; $01$ indicates success, $00$ indicates failure. By adjusting the style, the grid control can be made to simulate embedded buttons and checkboxes. Clicking on these simulated buttons and checkboxes does not generate any special event code. To simulate the operation of these controls, the application must check for mouse clicks or double-clicks the cells and react by redrawing them with a different style setting.

Examples

The following example shows Draw Cell - Grid SENDMSG() Function 54 used to change the background color, set checkbox styles, and display text in two cells:

sysgui=unt; open (sysgui)"X0"
print (sysgui)'window'(0,20,550,100,"Grid Sample",$00000082$,$ff$)
print (sysgui)'grid'(100,20,20,500,54,$9040$,3,3,5)
dim grid$:tmpl(sysgui,ind=1); rem DIMension grid information block
grid$=sendmsg(sysgui,100,20,0,$$); rem initialize grid information block
grid.backcolor$=$ffccff$,grid.buf$="checkbox"
grid.style=4,grid.col=1,grid.row=1; rem create checked checkbox
tf$=sendmsg(sysgui,100,54,0,grid$)
grid.style=8,grid.col=2,grid.row=1; rem create unchecked checkbox
tf$=sendmsg(sysgui,100,54,0,grid$)
escape

The following example shows SENDMSG() Function 54 used to change default grid appearance and populate a grid with data:

sysgui=unt; open (sysgui)"X0"
print (sysgui)'window'(50,50,200,150,"Grid Sample",$$,$$)
print (sysgui)'grid'(100,20,20,160,120,$9040$,8,3,3)
result$=sendmsg(sysgui,100,68,150/4,$$); rem row height
result$=sendmsg(sysgui,100,57,0,$$); rem turn off color change highlighting
dim grid$:tmpl(sysgui,ind=1); rem DIMension grid information block
grid$=sendmsg(sysgui,100,20,0,$$); rem initialize grid information block
grid.style=1; rem set cell style to raised button
counter=0
for col=0 to 2
result$=sendmsg(sysgui,100,36,col,chr(51)); rem column width
for row=0 to 2
rem Instruct SENDMSG(54) which cell to manipulate
grid.col=col,grid.row=row
rem Set display buffer to loop counter.
grid.buf$=str(counter)
tf$=sendmsg(sysgui,100,54,0,grid$)
counter=counter+1
next row
next col
escape

The following example shows SENDMSG() Function 54 used to create a checkerboard pattern with varying background colors and styles. Note that by setting values for grid.buf$, this code could also display data in the grid:

sysgui=unt; open (sysgui)"X0"
print (sysgui)'window'(50,50,200,150,"Grid Sample",$$,$$)
print (sysgui)'grid'(100,20,20,160,120,$9040$,8,3,3)
result$=sendmsg(sysgui,100,68,150/4,$$); rem row height
result$=sendmsg(sysgui,100,57,0,$$); rem turn off color change highlighting
dim grid$:tmpl(sysgui,ind=1); rem DIMension grid information block
grid$=sendmsg(sysgui,100,20,0,$$); rem initialize grid information block
counter=0
for col=0 to 2
result$=sendmsg(sysgui,100,36,col,chr(51)); rem column width
for row=0 to 2
rem Instruct SENDMSG(54) which cell to manipulate
grid.col=col,grid.row=row
rem Based on counter value, set style and background color
if mod(counter,2) then
: grid.style=2,grid.backcolor$=$ffcc00$
: else
: grid.style=0,grid.backcolor$=$ffffff$
tf$=sendmsg(sysgui,100,54,0,grid$)
counter=counter+1
next row
next col
escape