A DataGrid is not a spreadsheet

Bob Sneidar bobsneidar at iotecdigital.com
Fri Aug 5 11:59:55 EDT 2016

I happen to think that editing a data grid as a means of updating a database is a little messy. What I do is I have a form for every table (I use a separate stack for each table because I can manage the custom behaviors for each application more effectively). I name the fields "fld" & the column name from the table so it's easy to write loops that can populate or extract data from my forms. 

In fact that is exactly what I do. I have a populate and extract handler in a backscript that I call whenever the selection of the datagrid changes. (on selectionChanged) I pass those handlers an array of the datagrid record (the dgDataOfLine or dgDataOfIndex). The handlers check for the existence of a field with the same name as the table column. (if there is a field "fldCustomerName" for ex.) If the field exists, it puts the value from the table column into the field (or in the case of extract, gets the value from the field and sets the array value). 

To make this method scalable, I get ALL the columns for a particular record when I query the table, and I populate the datagrid with all that data. This approach allows me to simply create a new table column, add a corresponding field to my form, and voila! It populates and extracts without having to do anymore coding. Also, since I have the unique index I have a pointer back to the record in the table the data belongs to. Note that the datagrid will only display the data you tell it to when you define the data grid. So you can have the datagrid display key fields while the form fields give the user more detail. (For instance, a site datagrid can display site name, city and state, while the fields can have address and contact info). 

I have improved my extract and populate handlers so that they also handle buttons and menus. This required me to store the values in the sql table in the same format as the button or menu uses. For instance a checkbox uses true or false for hilited, so I use a varchar(5) column instead of a boolean to store that value so I do not have to worry about conversions going into and out of the table. I don't get terrible wound up trying to make my sql tables as compact as possible. 

I'll send you some screen shots to give you an idea of what I am doing to your direct email. 


Bob S

> On Jul 28, 2016, at 19:24 , Javier Miranda V. <jemirandav at gmail.com> wrote:
> Dear friends, is it safe to say that a data grid is not a spreadsheet? I mean, you can not create a new data grid and then just click in a empty cell and enter data. 
> With some practice and reading documentation, I am able to populate a datagrid with data from a database, and using a Table field in situation in which the user must fill-in data seems limited.  
> Saludos, 
> Javier Miranda V.
> _______________________________________________
> 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

More information about the Use-livecode mailing list