DataGrid column update and button center

zryip theSlug zryip.theslug at gmail.com
Mon Aug 9 06:38:10 EDT 2010


On Fri, Aug 6, 2010 at 12:02 PM, Scott Morrow
<scott at elementarysoftware.com> wrote:

Hi Scott,

> Two Data Grid questions:
>
> 1)     I'm updating a single column of a Data Grid table.  I can't discover any other way than to loop through each index.  Would this be the accepted method?
>
> --- the code I'm using -------------------------------------------
>
> put the dgData["false"] of grp "DataGrid 1" into tArray
> put 1 into tIndexCounter
>  -- the column data might look like this as I'm setting the hilite of checkBox buttons
> put "true,true,false,true" into tNewColumnData
>
> repeat for each item tNewData in tNewColumnData
>     put tNewData into tArray[tIndexCounter]["theColumnName"]
>     add 1 to tIndexCounter
> end repeat
>
> set the dgData of grp "DataGrid 1" of stack "myStackName" to  tArray
> ---------------------------------------------------------------------

Using a loop is the only way I know.
You can also update the array by using the DataGrid API, with the
SetDataOfIndex (or SetDataOfLine).
It is equivalent to your loop excepted that you have not to refresh
the whole data, only the data required by the column.
It means that by using the SetDataOfIndex, set the dgData of the DG is
not required.

Note that in this line
put the dgData["false"] of grp "DataGrid 1" into tArray

the dgData properties not accepts a parameter. Only dgText do.

> 2)     I have a column of checkbox buttons.  The column header is wider than the
> button(s) and I would like to be able to center the button(s) in the column.  It seems like I
>should be able to do this (using the DataGrid inspector) by setting the
> dgColumnAlignment to "center" but I'm not having any luck.  Any suggestions (hoping I
> don't need to switch to a "form" layout"  :  )

The dgColumnAlignment is only provided to change the alignment of a
standard column (text and not managed by a custom behavior)
To "center" a checkbox, you have to manage it in the LayoutControl
event of the column behavior.

on LayoutControl  pControlRect
    centerMyCheckBox -- center the checkbox in the rect (pControlRect)
of the cell
end LayoutControl

So no need to switch to a DG form ;)


Regards,

-- 
-Zryip TheSlug- wish you the best! 8)
http://www.aslugontheroad.co.cc



More information about the use-livecode mailing list