Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!
I am trying to set the cell color to green if the cell entry is 1, red if it is 0. I added a switch statement to the FillinData handler of the behavior script, as follows:
on FillInData pDataArray
set the text of field "Label" of me to pDataArray["label 1"]
switch the text of field "Label" of me
case 1
set the backGroundColor of me to green
case 0
set the backGroundColor of me to red
end switch
end FillInData
well, ME in your script refers to the datagrid itself and there is nothing that could HEIR this backgroundcolor obviously!
Maybe because the objects have their own bg color set?
But you actually want to colorize a certain FIELD, right?
In that case try this:
...
switch the text of field "Label" of me
case 1
set the backGroundColor of fld "Label" of me to green
case 0
set the backGroundColor of fld "Label" of me to red
end switch
...
1. It has to be set in the fillinData of the custom column behavior script, not the dataGrid behavior script
2. The opacity must be set to "true" (default is "false", so the background bands of alternating row colors could show)
on FillInData pData
set the text of field 1 of me to pData
if the text of field 1 of me is 1 then
set the opaque of me to true
set the backgroundColor of me to green
else
set the opaque of me to true
set the backgroundColor of me to red
end if
end FillInData
Hi, I know that this is a very old post but it is probably worth adding that the example above uses a "custom column behavior script" which works with a single column. If you want the colours to be applied across all the columns then the same code should be used in a behavior button that is set as the "default column behavior". This is set using commands like:
Set the dgProps["default column behavior"] of group "DgLCSS" to the SelObj()
(see page 126 of the datagrid guide).
It is also worth noting that it is possible to set the colour of the text in FillInData but that it gets reset when "setprop dgHilite pBoolean" is called. Despite what is written in the comments :
setprop dgHilite pBoolean
-- This custom property is set when the highlight of your column template has
-- changed. You only add script here if you want to customize the highlight.
if pBoolean then
set the foregroundColor of me to the dgProp["hilited text color"] of the dgControl of me
else
set the foregroundColor of me to empty
end if
end dgHilite
This is called after every row has been populated which means that the colour you set is very short lived.
on mouseUp
set the opaque of fld "col 3 0002" of grp 1 to "true" --have to do this as well
set the backgroundColor of fld "col 3 0002" of grp 1 to "red"
end mouseUp
Each field in a new DG is named in row/column format. Beyond that, they are all just LC field objects, and can be managed by hand.
Simon Knight wrote:It is also worth noting that it is possible to set the colour of the text in FillInData but that it gets reset when "setprop dgHilite pBoolean" is called. Despite what is written in the comments :
setprop dgHilite pBoolean
-- This custom property is set when the highlight of your column template has
-- changed. You only add script here if you want to customize the highlight.
if pBoolean then
set the foregroundColor of me to the dgProp["hilited text color"] of the dgControl of me
else
set the foregroundColor of me to empty
end if
end dgHilite
This is called after every row has been populated which means that the colour you set is very short lived.
Off the top of my head....
You could save the text color as a custom property in the FillinData handler