data grid code (color)
sadhu at castandcrew.com
Fri Apr 17 19:13:05 EDT 2009
Note that you may also double click on a cell and edit it directly, and
again, the expected behavior is, if you type foo, it turns red. The
refreshlist command is supposed to be called upon editing but I added
this as a separate button choice just in case, didn't help.
Sadhu Nadesan wrote:
> 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.
> The goal is to add a custom behavior that will turn certain cells
> color upon a certain condition.
> 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
> -- 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 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.
>>> Let me know if this helps.
More information about the Use-livecode