Form Data Grid - Setting Background Row Color

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Tester2
Posts: 102
Joined: Wed May 18, 2011 7:02 pm

Form Data Grid - Setting Background Row Color

Post by Tester2 » Thu Nov 14, 2013 10:06 pm

Is there a way to change the background color on specific rows of a form data grid?

Ex: If I want row 1 and 5 to have a background color of white, but the other rows (2,3,4,6,7) to have background colors of red - how would I accomplish this?

I tried the code below, but it did not work:

set the backgroundcolor of line 2 of grp "DataGrid 1" of grp "Scroller" to 248,247,249

Thanks!

-Milo

Jellicle
Posts: 453
Joined: Thu Feb 24, 2011 11:07 am

Re: Form Data Grid - Setting Background Row Color

Post by Jellicle » Fri Nov 15, 2013 2:50 am

What I would do is place a coloured graphic object behind everything else in the Row Template group, sized the same as the group.

I'm assuming there is some condition that needs to be met for the graphic to show - when it's met for the record do:

Code: Select all

set the visible of graphic "redBackground" of me to true
Gerry
14" MacBook Pro
Former LiveCode developer.
Now recovering.

Tester2
Posts: 102
Joined: Wed May 18, 2011 7:02 pm

Re: Form Data Grid - Setting Background Row Color

Post by Tester2 » Fri Nov 15, 2013 3:27 am

Gerry,

Thanks so much for the response!

I am just trying to color certain rows indefinitely - they will not change color based on a condition.

I have some rows that I am just using as Headers.

Example:

Row 1: Introduction
Row 2: Video 1
Row 3: Video 2
Row 4: Video 3
Row 5: Overview
Row 6: Video 4
Row 7: Video 5

In this example, I want to have the background color for Row 1 and Row 5 to be white….but the other rows to have a background color of blue.

Thanks for your help!

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Form Data Grid - Setting Background Row Color

Post by Simon » Fri Nov 15, 2013 3:58 am

Hi Tester2,
I think Gerry's answer still holds true.
Just add a graphic, show it for rows 1-5 hide it for the rest. Somewhere in your preOpenCard maybe?

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Tester2
Posts: 102
Joined: Wed May 18, 2011 7:02 pm

Re: Form Data Grid - Setting Background Row Color

Post by Tester2 » Fri Nov 15, 2013 4:14 am

Thanks for the comment Simon…I'm hoping you are correct!

I added a "redBackground" graphic in my Row Template group.

I think that I am maybe using the wrong terminology in my code.

This is the command I am trying to use to set the 3rd row's background to red:

set the visible of line 3 graphic "redBackground" of grp "DataGrid 1" of grp "Scroller1" to true

Side Note: I have a Form Data Grid (DataGrid 1) inside of a MobGui Scroller (Scroller1).

Thanks!

Jellicle
Posts: 453
Joined: Thu Feb 24, 2011 11:07 am

Re: Form Data Grid - Setting Background Row Color

Post by Jellicle » Fri Nov 15, 2013 4:45 am

You do have a condition: is this row a header record or is it not? If it's a video - show the blue background. If it's not...hide it.

I assume you are filling the data grid with an array? And that you are using the Data grid template Behaviour Script to place the array data into fields? Your code to show or hide the background graphic goes in that behaviour script.

Your array should contain a field (say "rowtype") that specifies whether the row is a header or not. A true/false flag in that field will do.

Then in the behaviour script you need to check which record in the array is currently being processed and if it is one of your header rows then hide the background graphic, else show it.

And your code (in the LayoutControl handler) would be something like:

Code: Select all

if pDataArray["rowtype"] = "false" then
 set the visible of graphic "blueBackground" of me to false
else
set the visible of graphic "blueBackground" of me to true
end if
Gerry
14" MacBook Pro
Former LiveCode developer.
Now recovering.

Jellicle
Posts: 453
Joined: Thu Feb 24, 2011 11:07 am

Re: Form Data Grid - Setting Background Row Color

Post by Jellicle » Fri Nov 15, 2013 4:52 am

...or are you wanting to set those row colours from outside the data grid behaviour script?

Gerry
14" MacBook Pro
Former LiveCode developer.
Now recovering.

Tester2
Posts: 102
Joined: Wed May 18, 2011 7:02 pm

Re: Form Data Grid - Setting Background Row Color

Post by Tester2 » Fri Nov 15, 2013 6:14 am

Gerry,

These little grids are much bigger than I expected! lol

I explored your option and after some testing and modifying was able to get it to work! :)

I think I just need some more experience with them, and it will get easier.

Thanks a million for your help!

-Milo

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Form Data Grid - Setting Background Row Color

Post by Klaus » Fri Nov 15, 2013 1:07 pm

See Milo, professional help is guaranteed when:
1. not hijacking another thread and
2. posting in the correct forum
:D

Jellicle
Posts: 453
Joined: Thu Feb 24, 2011 11:07 am

Re: Form Data Grid - Setting Background Row Color

Post by Jellicle » Fri Nov 15, 2013 11:52 pm

Milo

Datagrids have a steep learning curve, but are totally worth it :)

Gerry
14" MacBook Pro
Former LiveCode developer.
Now recovering.

Post Reply