How to set the background color in the data grid cell / row/ colum

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!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
lemodizon
Posts: 207
Joined: Thu Apr 05, 2018 3:33 pm

How to set the background color in the data grid cell / row/ colum

Post by lemodizon » Wed Jul 10, 2024 1:16 pm

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

Thank you & God Bless Everyone :wink:

Regards,
lemodizon

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9848
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: How to set the background color in the data grid cell / row/ colum

Post by dunbarx » Wed Jul 10, 2024 3:22 pm

Maybe this?

put the dgProp["row color"] of group "Data Grid"

Perhaps the "put" can be changed to "set"?

Craig

stam
Posts: 2845
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: How to set the background color in the data grid cell / row/ colum

Post by stam » Wed Jul 10, 2024 5:53 pm

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...

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9848
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: How to set the background color in the data grid cell / row/ colum

Post by dunbarx » Wed Jul 10, 2024 8:50 pm

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

stam
Posts: 2845
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: How to set the background color in the data grid cell / row/ colum

Post by stam » Wed Jul 10, 2024 8:59 pm

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.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9917
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: How to set the background color in the data grid cell / row/ colum

Post by FourthWorld » Wed Jul 10, 2024 9:17 pm

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

stam
Posts: 2845
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: How to set the background color in the data grid cell / row/ colum

Post by stam » Wed Jul 10, 2024 9:27 pm

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...

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9917
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: How to set the background color in the data grid cell / row/ colum

Post by FourthWorld » Wed Jul 10, 2024 10:32 pm

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

stam
Posts: 2845
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: How to set the background color in the data grid cell / row/ colum

Post by stam » Wed Jul 10, 2024 10:55 pm

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 :P :P :P

I think it’s now Lemodizon’s turn to actually clarify what is being asked as we’ve probably answered every eventuality by now ;)

lemodizon
Posts: 207
Joined: Thu Apr 05, 2018 3:33 pm

Re: How to set the background color in the data grid (ROW OR CELL))

Post by lemodizon » Thu Jul 11, 2024 1:34 am

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
Datagridbackground_row.png
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
Thank you & God Bless Everyone :wink:

Regards,
lemodizon

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9848
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: How to set the background color in the data grid cell / row/ colum

Post by dunbarx » Thu Jul 11, 2024 2:30 pm

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

stam
Posts: 2845
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: How to set the background color in the data grid cell / row/ colum

Post by stam » Thu Jul 11, 2024 2:58 pm

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.
Last edited by stam on Sat Jul 13, 2024 7:28 pm, edited 1 time in total.

bobcole
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 139
Joined: Tue Feb 23, 2010 10:53 pm
Location: Saint Louis, Missouri USA

Re: How to set the background color in the data grid cell / row/ colum

Post by bobcole » Fri Jul 12, 2024 8:46 pm

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

lemodizon
Posts: 207
Joined: Thu Apr 05, 2018 3:33 pm

Re: How to set the background color in the data grid cell / row/ colum

Post by lemodizon » Sat Jul 13, 2024 4:58 am

bobcole wrote:
Fri Jul 12, 2024 8:46 pm
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
Hi bobcole

Thanks for the link post i will check on and try it.
Thank you & God Bless Everyone :wink:

Regards,
lemodizon

stam
Posts: 2845
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: How to set the background color in the data grid cell / row/ colum

Post by stam » Sat Jul 13, 2024 7:25 pm

bobcole wrote:
Fri Jul 12, 2024 8:46 pm
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
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.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”