sample data grid code?

Trevor DeVore lists at
Sat Apr 11 00:35:58 EDT 2009

On Apr 10, 2009, at 5:05 PM, sadhu at wrote:

> What I really want to do is this;  have the data grid scroll, or focus
> change if that is the right terminology, to visibly show the cell  
> that is
> being processed, and then cycle through every row, top to bottom,  
> and on
> each row cycle through every cell, left to right, and then perform  
> some
> action on the data in each cell (such as turn it red if it is  
> invalid).
> I would like the user to be able to visually see the progress as the
> validity check is processing.
> I think this will make a very appealing app, not to mention,  
> useful.  For
> example, something the Java guys in our shop would be hard pressed  
> to say
> "we can do that".  At least, in the same time frame.  :-)

Thanks for the additional info Sadhu. When working with a data grid  
you update the UI by changing the data in the internal data grid  
array. Updating the data associated with a data grid triggers messages  
to be sent to the controls displaying that data.

You can update all of the data at once by setting the dgData or dgText  
properties or you can update individual indexes/lines by setting the  
dgDataOfIndex/dgDataOfLine. If you just want to update a specific key/ 
column then you can use SetDataOfIndex/SetDataOfLine. Further info on  
each of these is available here:


Now, when you update data in the data grid the UI elements associated  
with the index or line you are changing are updated. The data grid  
update the UI by sending the FillInData message to your row/column  

With that background let's look at your particular question. You want  
to perform some validation checks on each row in the data grid and  
visually represent those validation checks to the user. Let's assume  
you have already populated the data grid with some data and there are  
no visual cues as to whether or not the  data is valid. Now you want  
to go through each line one by one and validate. Here is how you might  
approach it:

* Set up a repeat loop that goes through each line in the data grid.
* For each line set a flag in the data grid that signifies that the  
data should be validated.
* In the FillInData message only show validation UI elements if the  
flag is set.

Some example code follows that is entirely untested :-)

====== Repeat Loop ======

repeat with theLineNo = 1 to the dgNumberOfLines of group "DataGrid"
     lock screen
     ## set flag so line redraws with validation
     dispatch "SetDataOfLine" to group "DataGrid" with theLineNo,  
"validate", true

     ## Scroll line into view
     dispatch "ScrollLineIntoView" to group "DataGrid" with theLineNo
     unlock screen

     ## A slight delay so user can see validation happening
     wait 100 milliseconds
end repeat

====== FillInData Code For a Column ======

on FillInData pData
     ## Is the validation flag set for particular row?
     if GetDataOfIndex (the dgIndex of me, "validate") is true then
         ## perform validation
         put MyDataValidationRoutine(pData) into theDataIsValid
         if theDataIsValid then
             set the backgroundColor of graphic 1 of me to "blue"
             set the backgroundColor of graphic 1 of me to "red"
         end if
         ## no validation
         set the backgroundColor of me to empty
     end if
end FillInData

Does the above make sense? If it does, does it do what you want?


Trevor DeVore
Blue Mango Learning Systems    -

More information about the use-livecode mailing list