Page 1 of 1
How to set the background color in the data grid cell / row/ colum
Posted: Wed Jul 10, 2024 1:16 pm
by lemodizon
hi everyone,
good day.
I was trying to set a background color of the data grid per row if this is possible in livecode.
here is my code i'm stuck on what next code will i enter. hope you can guide me
thanks in advance
Code: Select all
on mouseUp tMouseButton
global tLineToSelect
if tMouseButton <> 1 then
exit mouseUp
end if
put empty into tLineToSelect
put the dgHilitedLine of group "SbCustOrderList" into tLineToSelect
if tLineToSelect is not a number or tLineToSelect <= 0 then
exit mouseUp
else
set the itemdel to tab
put line tLineToSelect of the dgtext of grp "SbCustOrderList" into tData
FillInData
end if
end mouseUp
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.
set the text of me to pData
SetForeGroundColor
end FillInData
Re: How to set the background color in the data grid cell / row/ colum
Posted: Wed Jul 10, 2024 3:22 pm
by dunbarx
Maybe this?
put the dgProp["row color"] of group "Data Grid"
Perhaps the "put" can be changed to "set"?
Craig
Re: How to set the background color in the data grid cell / row/ colum
Posted: Wed Jul 10, 2024 5:53 pm
by stam
Where needed I’ve added a rect to the column (table) or row (form) prototypes, and show/hide this depending on whatever condition I need (I presume you are not referring to the hilitedRow/index).
AFAIK, “cells” in a DG table don’t have a background colour otherwise because there aren’t any actual “cells” in a DG...
Re: How to set the background color in the data grid cell / row/ colum
Posted: Wed Jul 10, 2024 8:50 pm
by dunbarx
Stam.
because there aren’t any actual “cells” in a DG...
True. But the OP asked for setting the color of a row. I just do not know for sure if the property I mentioned is read-only or not.
Craig
Re: How to set the background color in the data grid cell / row/ colum
Posted: Wed Jul 10, 2024 8:59 pm
by stam
dunbarx wrote: ↑Wed Jul 10, 2024 8:50 pm
But the OP asked for setting the color of a row. I just do not know for sure if the property I mentioned is read-only or not.
Craig
Hi Craig, dgProp["row color"] affects
all rows, or is the primary color if set to alternating rows.
I understood the OP asking how to highlight a
specific row (and assumed this wasnt' the obvious dgHilitedRow).
lemodizon wrote: ↑Wed Jul 10, 2024 1:16 pm
I was trying to set a background color of the data grid
per row if this is possible in livecode.
I may well have misunderstood and @lemodizon just wants to set all rows -then yes, completely agree the dgProp is the way to go. And yes this is a settable property (in fact, it's the prop you modify in the property inspector).
If on the other hand rows should for example take a color depending on a value, then I think the only way to go is to add a background graphic to the column or row (for table or form DG respectively).
S.
Re: How to set the background color in the data grid cell / row/ colum
Posted: Wed Jul 10, 2024 9:17 pm
by FourthWorld
I can't recall the syntax offhand and I'm not at my computer to look it up, but I'm pretty sure DG includes a property for coloring alternate lines. It's a very common need, and IIRC every UI I've used it in employed that feature.
Re: How to set the background color in the data grid cell / row/ colum
Posted: Wed Jul 10, 2024 9:27 pm
by stam
Hi Richard,
not sure anyone was talking about alternate row colors, but in any case: These are all properties modifiable in the property inspector -
unless you want to color a specific, non-hilited row, or for example color rows differently depending on a value, which requires workarounds.
If set in LC's preferences to show the property name instead of the property description its easier to divine whether these are dgProps or just normal properties.
.
For those properties in the property inspector that have multiple words not in camelCase (for this your specific point, "alternate row colors") then this is going to be a dgProp instead of a property, ie
Code: Select all
set the dgProp["alternate row colors"] of group <gridname> to true|false
But this is not what @lemodizon appears to be asking in the original post, unless I've misunderstood. What I understood (and I very well may be wrong) is how to set the color of a specific (not hilighted) row...
Re: How to set the background color in the data grid cell / row/ colum
Posted: Wed Jul 10, 2024 10:32 pm
by FourthWorld
stam wrote: ↑Wed Jul 10, 2024 9:27 pm
Hi Richard,
not sure anyone was talking about alternate row colors...
From your post I replied to:
stam wrote: ↑Wed Jul 10, 2024 8:59 pm
Hi Craig, dgProp["row color"] affects
all rows, or is the primary color if set to alternating rows.
...
I may well have misunderstood and @lemodizon just wants to set all rows ...
And from your most recent:
What I understood (and I very well may be wrong) is how to set the color of a specific (not hilighted) row...
We're all just guessing at what lemodizno is asking for. You zeroed in on a specific possibility, I'd addressed the most common use case. And as is the tradition of these forums, not understanding the request hasn't stopped us from providing solutions.
When he returns to tell us what he needs, we'll see which of the many solutions here does what he's looking for.
Re: How to set the background color in the data grid cell / row/ colum
Posted: Wed Jul 10, 2024 10:55 pm
by stam
That is a great way to demonstrate the misunderstandings lol…
From:
- Lemidizon asking how to change backroundColor “per row”
- to Craig suggesting they change row color property
- to me pointing out that won’t affect specific rows and just explaining where that property applies, which just happened to mention alternate rows,
- to you actually zeroing in that last bit...
And still we don’t know what is actually being asked lol
I think it’s now Lemodizon’s turn to actually clarify what is being asked as we’ve probably answered every eventuality by now

Re: How to set the background color in the data grid (ROW OR CELL))
Posted: Thu Jul 11, 2024 1:34 am
by lemodizon
Hi everyone,
Good day.
First of all thank you for your response in my post.
Thank you for sharing your knowledge.
here is the picture i want to do
When the user clicked the button the whole
ROW will turn into Red background and when clicked the button again it will return into default color.
OR
When the user clicked the button a particular
CELL will turn into Red background and when clicked the button again it will return into default color.
Hope you can help me guys
thanks in advance
Re: How to set the background color in the data grid cell / row/ colum
Posted: Thu Jul 11, 2024 2:30 pm
by dunbarx
lemodizon.
If Stam is correct that the DG property I mentioned pertains only to ALL rows (and Stam us usually right) then his suggestion of a colored overlay is likely the only way to do what you want. This is a kludge, but that is not an issue if managed carefully. I have used such things forever. Let us know if you need a hand with that.
Craig
Re: How to set the background color in the data grid cell / row/ colum
Posted: Thu Jul 11, 2024 2:58 pm
by stam
Well, if you just want to change the color of the row the user selected (the dgHilitedRow) - which judging by the pic may well be what you need, then instead you could set the dgProps["hilite color"] to the desired color and then set it to empty to reset.
Code: Select all
set the dgProp["hilite color"] of group "DataGrid 1" to "red"
set the dgProp["hilite color"] of group "DataGrid 1" to empty
This will change the colour for the
selected row(s). if the row is no longer selected, the colour will go away.
However, if you want this behavior to be possible for
non-hilighted-rows, or if the colouring is to be permanent until a change happens, for example you want to turn the row red when the stocks are low or some such, you'll want to control your own background graphic for this (this is pretty much what the DG does to hilite a row, but using the default graphic "background" you see when editing the template).
I personally add a semitransparent graphic behind the contents in the template, adjust it's size accordingly in the
layoutControl handler and set it's visible and/or colour in the fillInData handler. You'll need to refresh the DG to update it.
Also be aware that if you want this change to happen for a table DG, you'll need to added to each column template.
One of the reasons I prefer to use form DG.
S.
Re: How to set the background color in the data grid cell / row/ colum
Posted: Fri Jul 12, 2024 8:46 pm
by bobcole
Stam once post a stack that may contain an answer to the question.
See this post:
viewtopic.php?f=7&t=37222&p=217243&hili ... ed#p217233
Bob
Re: How to set the background color in the data grid cell / row/ colum
Posted: Sat Jul 13, 2024 4:58 am
by lemodizon
Hi bobcole
Thanks for the link post i will check on and try it.
Re: How to set the background color in the data grid cell / row/ colum
Posted: Sat Jul 13, 2024 7:25 pm
by stam
Well spotted Bob - I had forgotten I posted that

But it does what I stated above - use a graphic as the background of the "cell" and control it's color programmatically.