How to develop and deploy with ListMagic within the GLX application framework?

Bob Sneidar bobs at twft.com
Fri Mar 4 13:24:17 EST 2011


What really helped me take hold of the reigns of datagrids is the notion of getting the index (or line) of a data control, getting the array associated with that line, altering the array, and then setting the array in the datagrid when I was done. 

This process is actually quite simple. Lets say a user clicked on a line in a table form and you want to process it somehow. Consider the following:

    put the dgHilitedIndex of group "myDataGrid" into theIndexNumber -- a number referencing the row array

    if theIndexNumber is empty then  -- nothing selected
        exit mouseUp
    end if
    
    put the dgDataOfIndex[theIndexNumber] of group "myDataGrid" into aMyData -- an array
    put aMyData["column1"] into theFirstValue -- a value. column1 is the actual name of your column. 
    put aMyData["column2"] into theSecondValue
    put aMyData["column3"] into theThirdValue

Now go do some stuff with the data, and when you are done: 

    put theFirstValue aMyData["column1"] into aMyData["column1"]
    put theSecondValue aMyData["column2"] into aMyData["column2"]
    put theThirdValue aMyData["column3"] into aMyData["column3"]
    set the dgDataOfIndex[theIndexNumber] of group "myDataGrid" to aMyData -- update the row

Sometimes it is easier to work with the data grid data as a chunk of text:

    put the dgtext ["false"] of group "myDataGrid" into theGridData -- tab/cr delimited list

false means the first row does not contain the column names. In this mode it will simply use the position of the column as the index to the data in the column. If you use true, then the first line of your text needs to be the column names. This can be handy when you want to update only certain columns but leave the others intact. When done processing: 

    set the dgtext ["false"] of group "myDataGrid" to theGridData -- put the data back

While the Datagrid tutorial and API is very useful, and I recommend it for the first time use of data grids, it doesn't actually list everything you can do with a datagrid. To see all the commands and functions available to the data grid, issue this command:

edit the script of the behavior of group "myDataGrid". 

Simple huh? What would be nice is if I could pass the column names off to dgText so that I only got the columns I wanted. The beauty is though, that I can copy the behavior scripts to a new button, set the behavior of the datagrid to that button, and then make it do things the way I want to. 

Bob


On Mar 4, 2011, at 8:34 AM, Keith Clarke wrote:

> Hi Trevor,
> Thanks for confirming that this behaviour is not coming from the GLX framework. 
> Maybe it's time to bite the bullet and replace my simple ListMagic controls with data grids - and learn how to drive them and DGH properly! ;-)  





More information about the use-livecode mailing list