According to the documentation for the Grid interface, there’s three relevant attributes:
.bycellcontrols whether individual cells in the grid can be selected.rowcontrols which row of the grid is selected.colcontrols which column of the grid is selected
You can select row 1, column 2 of a grid like this:
grid1.bycell:1
grid1.row:1
grid1.col:2
The “select by cell” option can be set in the properties window for the grid, but if it can get cleared by some other code, you’ll need to re-set it.
There’s one other quirk I noticed. Normally, if something in Decker needs to be a number, Decker will automatically convert it. For example, grid1.row:"1" will select a cell in row 1 though "1" is a string, because the row number needs to be an integer so it gets converted. However, the .col property does not work the same way. grid1.col:2 will select the cell in column 2, but grid1.col:"2" selects nothing. This can be a problem if the column number you’re trying to set comes from a field value, or gets read from a file. To force it to be handled as a number, you can do something like add zero: grid1.col:0+"2"
Here’s a card you can paste into your deck to play with reading a grid’s selected cell, and selecting one with code.
%%CRD0{"c":{"name":"home","script":"on view do\n bycell.value:grid1.bycell\n row.text:grid1.row\n col.text:grid1.col\nend","widgets":{"grid1":{"type":"grid","size":[96,64],"pos":[48,64],"script":"on click row do\n view[]\nend","bycell":0,"value":{"a":["1","4","7"],"b":["2","5","8"],"c":["3","6","9"]},"row":2,"col":2},"bycell":{"type":"button","size":[64,16],"pos":[160,64],"script":"on click do\n grid1.bycell:me.value\nend","text":"By Cell","style":"check","value":0},"field1":{"type":"field","size":[32,16],"pos":[160,80],"locked":1,"font":"menu","border":0,"style":"plain","value":"Row"},"field2":{"type":"field","size":[48,16],"pos":[160,96],"locked":1,"font":"menu","border":0,"style":"plain","value":"Column"},"row":{"type":"field","size":[32,16],"pos":[208,80],"script":"on change val do\n grid1.row:val\nend","style":"plain","value":"2"},"col":{"type":"field","size":[32,16],"pos":[208,96],"script":"on change val do\n grid1.col:0+val\nend","style":"plain","value":"2"}}},"d":{}}
Note:
- the card has a
viewhandler that copies the state of the grid’s properties into the thebycell,rowandcolfields - the
bycell,row, andcolfields have code that set the state of the grid when the field is changed - the
colfield has the extra0+trick to make it work likerowdoes