Scrolling of DataGrid driven by Database on IOS

Terry Judd tsj at unimelb.edu.au
Mon Nov 14 18:21:56 EST 2011


On 15/11/2011, at 09:22 AM, Michael Doub wrote:

> Does anyone have an example of a DataGrid form with non fixed height rows being directly loaded from the database that is also hooked up to the IOS scroller?
> 
> Yes I am being kind of specific here.   I have found examples for large datasets using data grids, but none of which have variable hight rows.  Hooking it up to the IOS scroller is interesting because I don't know how one would figure out the "contentRect" of the scroller.

I create a locked group containing the datagrid that is set to the dimensions. I then populate the datagrid (usually with data fetched from a database via a PHP script and converted to an array) and set its height based on ALL the records it contains.
So, for example if my datagrid is name myData_DG, I place it in a locked and sized group called myData. And do something like this...

set the dgData of grp "myData_DG" to tData
set the height of grp "myData_DG" to the max((the dgFormattedheight of grp "myData_DG"),(the height of grp "myData"))

then to setup the scroller, something like...

local pScrollerID, pScrollerGrp
iphoneControlCreate "scroller"
put the result into pScrollerId
put "myData" into pScrollerGrp
put the rect of grp pScrollerGrp into theGridRect
iphoneControlSet pScrollerId, "rect", theGridRect
# setup other scroller properties here
# now setup the scroller ContectRect
put (the dgFormattedHeight of group "myData_DG") into tHeight
put the width of group pScrollerGrp into tWidth
iphoneControlSet pScrollerId, "contentRect", (0,0, tWidth, tHeight)

If you're using a table datagrid then you'll need to create a separate 'header' (I use another datagrid for this) and 'link' it to the datagrid containing the data so that it will respond when you click the column names in the header to sort the datagrid.

My datagrids all have fixed line heights so if you're toggling rows and changing line heights in the process I guess you might need to reset the height of the datagrid using...

set the height of grp "myData_DG" to the max((the dgFormattedheight of grp "myData_DG"),(the height of grp "myData"))

and reset the scroller's content rect using...

put (the dgFormattedHeight of group "myData_DG") into tHeight
put the width of group pScrollerGrp into tWidth
iphoneControlSet pScrollerId, "contentRect", (0,0, tWidth, tHeight)

Not sure what toggling rows will do to the actual scroll value of the scroller however (could be messy).

Terry...

> 
> Thanks
>   Mike
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
> 

Dr Terry Judd
Senior Lecturer in Medical Education
Medical Eduction Unit
Faculty of Medicine, Dentistry & Health Sciences
The University of Melbourne








More information about the Use-livecode mailing list