data grid code (color)

Sadhu Nadesan sadhu at castandcrew.com
Fri Apr 17 19:10:29 EDT 2009


Trevor

You said, let you know.  Ok!

I must be doing something wrong, it doesn't seem to work.  On the other 
hand I did vary slightly from your instructions.  I will file this as a 
bug report so I can include a sample stack and screen shots.

Context

The goal is to add a custom behavior that will turn certain cells color 
upon a certain condition.

Problem

Attempting to apply the example logic in practice, nothing happens, no 
color change.

How to Duplicate This Problem

Create a new stack, very simple, with 2 objects, a populate button, and 
a data grid with 3 columns, with default names, that is group 
"datagrid", and columns "col 1", col 2", and "col 3".  Populate a few 
rows, say 3,  using the contents pane of the property inspector.

The populate button has this code  (assuming you haven't resorted, the 
row numbers and index numbers are the same)

on mouseUp
   ask "Pattern?"
   put it into thePattern
   repeat with rownum = 1 to 3
      dispatch "setdataofindex" to group "datagrid" with rownum, "Col 
2", thePattern
   end repeat
   dispatch "RefreshList" to group "datagrid"
end mouseUp


Note that the refreshlist call at the end is necessary or you won't see 
any changes.    The above will let you change the contents of column 2, 
the first 3 rows.

Next, select the data grid and using the property inspector, and in the 
columns choice, highlight col 2, then use the plus button at the bottom 
and then click column behavior to begin editing the custom behavior for 
this column.

To the fillindata handler, add some code to change the color depending 
on the contents of the cell.  Like this

on FillInData pData
   -- This message is sent when the Data Grid needs to populate
   -- this template with the column data. pData is the value to be 
displayed.
  
   -- Example:
   set the text of field 1 of me to pData
   if (pData contains "foo") then
      set the backgroundcolor of field 1 of me to "red"
   end if
end FillInData

Now run your stack.  put 'bar" in column 2, by clicking the populate 
button and answering bar.  Nothing should happen.  Now do it again and 
answer foo.  Again, nothing happens, but the foo cells were expected to 
be red.


Trevor, is my error obvious to the master?  What have I left out!

Grateful thanks,
Sadhu





Sadhu Nadesan wrote:
> Wow, Trevor, you are the MAN!  MAHALO!  I will check it out right away.
>
>> You should be able to get this working without too much trouble. 
>> I've  added a lesson to the manual that discusses how you can 
>> quickly  override the default column behavior for a data grid table. 
>> There are  two samples at the end of the lesson, one of which shows 
>> how to color  a cell.
>>
>> <http://revolution.screenstepslive.com/spaces/revolution_tools/manuals/datagrid/lessons/3966-How-Do-I-Override-the-Default-Behavior-For-Rendering-Data-to-a-Cell- 
>>  >
>>
>> Let me know if this helps.
>>
>> Regards,
>>   



More information about the use-livecode mailing list