Change datagrid backgroundcolor for a row from code [SOLVED]

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

Nicke
Posts: 36
Joined: Thu Nov 28, 2013 11:19 am
Location: Helsinki, Finland

Change datagrid backgroundcolor for a row from code [SOLVED]

Post by Nicke » Wed May 07, 2014 7:25 pm

Hi,

I have a datagrid (table) and I want to know how to change the backgroundcolor for a specific row without clicking on it (for example change the backgroundcolor of line 4 to red). I also want to know how to change the hilited "bar" to other rows in the datagrid from code without clicking on it.

Can someone point me to the right information or show me how to do it?

Thanks in advance!
Nicke
Last edited by Nicke on Fri May 23, 2014 7:53 am, edited 1 time in total.

Nicke
Posts: 36
Joined: Thu Nov 28, 2013 11:19 am
Location: Helsinki, Finland

Re: Change datagrid backgroundcolor for a row from code

Post by Nicke » Wed May 07, 2014 8:18 pm

Ok, I figured out how to change the hilited row...

Code: Select all

set the dgHilitedIndex of group "dataGrid" to 2
Now I just need help with the backgroundcolor

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

Re: Change datagrid backgroundcolor for a row from code

Post by dunbarx » Thu May 08, 2014 3:48 am

Hi.

Make a DG (hopefully this will be "grp 1"). Put several lines of data into it.

try this in a button somewhere:

Code: Select all

on mouseUp
    set the dgProp["hilite color"] of grp 1 to "cornflowerblue"
      set the dgHilitedLines of grp 1 to 2
end mouseUp
DataGrids are very powerful, but take some getting used to. The syntax and vocabulary are very LiveCode-like, but are comprised of a new set of commands and properties. Good luck.

Craig Newman

Nicke
Posts: 36
Joined: Thu Nov 28, 2013 11:19 am
Location: Helsinki, Finland

Re: Change datagrid backgroundcolor for a row from code

Post by Nicke » Thu May 08, 2014 6:50 am

Hi Craig,

thanks, yes they are kind of hard to understand :) I was actually interested in how to change the backgroundcolor of a row that is independent (not affected of user clicks in the DG) of what is hilited, sorry for the confusion.

BR Nicke

Nicke
Posts: 36
Joined: Thu Nov 28, 2013 11:19 am
Location: Helsinki, Finland

Re: Change datagrid backgroundcolor for a row from code

Post by Nicke » Fri May 09, 2014 11:26 pm

I have still not found a working solution for changing the background color of a line in a datagrid, any ideas? I would like to set the background color of a line that does not change (as the hilitebar does) if the user clicks in the datagrid.

BR Nicke

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

Re: Change datagrid backgroundcolor for a row from code

Post by dunbarx » Sat May 10, 2014 12:01 am

Hi.

I am not understanding now. The following code (as does my earlier) sets one or more lines of a DG to any color you want:

Code: Select all

on mouseUp
  set the dgFocus of grp 1 to "true"
    set the dgProp["hilite color"] of grp 1 to "red"
      set the dgHilitedLines of grp 1 to 2 -- or, perhaps, "1,3,5"
end mouseUp
What am I missing? Line 1 maintains focus on the DG. This can wander if one is not careful.

Craig

Nicke
Posts: 36
Joined: Thu Nov 28, 2013 11:19 am
Location: Helsinki, Finland

Re: Change datagrid backgroundcolor for a row from code

Post by Nicke » Sat May 10, 2014 7:03 am

Hi,

Craig, I will try to explain better what I want to achieve.

I started a new Main stack, I dragged a DataGrid out named it "DG1" added four columns, added 3 lines of data. Added a button with the code below:

Code: Select all

on mouseUp
   set the dgFocus of grp "DG1" to "true"
   set the dgProp["hilite color"] of grp "DG1" to "red"
   set the dgHilitedLines of grp "DG1" to 1
end mouseUp
When I click the button line 1 becomes selected with a red background, but when I click on line 3 the red selection moves to line 3.

What I want to happen is that when I run the code line 1 turns red (as now) and stays red no matter where I click in the datagrid after that. So that is why I think that the hilite color can not be used because I still want the user to be able to click and use the grid as usually (with hilite on the line choosen) but the background of line 1 should stay red until I change it from code again.

The idea here is that my datagrid is a playlist that shows what is playing on a server and the user can scroll the datagrid make changes to it (update columns, even choose a line and force the playback to jump to that line etc) but it must always show what the server is now playing.

Nicke

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

Re: Change datagrid backgroundcolor for a row from code

Post by Simon » Sat May 10, 2014 7:44 am

Hi Nicke,
Along with Craig's stuff, put this into the DG1 script:

Code: Select all

on mouseDown
   put the dgHilitedLines of me
   set the dgHilitedLines of me to 1
end mouseDown
Happens so fast you wont see it.

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

Nicke
Posts: 36
Joined: Thu Nov 28, 2013 11:19 am
Location: Helsinki, Finland

Re: Change datagrid backgroundcolor for a row from code

Post by Nicke » Sat May 10, 2014 8:07 am

Hi Simon,

I added your code to the DG but I'm still confused. So now (I'm testing this on a linux machine now, I usually use LC on a Windows if that is of any difference) when I click on any line in the DG the message box pops up with the command closeCard entered and below the line I pressed but the line is not hilited (it flashes red and goes back to line 1).

So unless I'm completely stupid (and doing all this wrong) I still think I need to set the backgroundcolor and not use the hilite because I still need the DG to behave as it would normally eg. the hilite bar should be another color than the row I wanted to have the red background and I should be able to move the hilited line with for example the arrow keys (and mouse) as usually and all this without changing the background of line 1 (in this example).

Nicke

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

Re: Change datagrid backgroundcolor for a row from code

Post by Simon » Sat May 10, 2014 8:17 am

Ahhhh...
So you do still want the clicked row to change color just the "currently playing" row to stay fixed with a.... ummm, different highlight?

Going to have to think about that.


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

Nicke
Posts: 36
Joined: Thu Nov 28, 2013 11:19 am
Location: Helsinki, Finland

Re: Change datagrid backgroundcolor for a row from code

Post by Nicke » Sat May 10, 2014 8:26 am

Simon,

correct.

The closest I have found is this http://ftp.runrev.com/forums/viewtopic.php?f=7&t=13025 solution but I have not figured out how I should use it from code (where I'm not clicking on the datagrid)...

Nicke

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

Re: Change datagrid backgroundcolor for a row from code

Post by Simon » Sat May 10, 2014 8:40 am

Yeah, Sri had it right.

on mouseUp
set the opaque of field "Col 2 0002" of grp "DG1" to true
set the backgroundColor of field "Col 2 0002" of grp "DG1" to "green"
end mouseUp

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

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

Re: Change datagrid backgroundcolor for a row from code

Post by Simon » Sat May 10, 2014 8:44 am

Code: Select all

on mouseUp
   repeat with x = 1 to 4
      set the opaque of field ("Col" && x &&  "0002") of grp "DG1" to true
      set the backgroundColor of field ("Col" && x &&  "0002") of grp "DG1" to "green"
   end repeat
end mouseUp
Probably more what you are after

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

Nicke
Posts: 36
Joined: Thu Nov 28, 2013 11:19 am
Location: Helsinki, Finland

Re: Change datagrid backgroundcolor for a row from code

Post by Nicke » Sat May 10, 2014 8:57 am

Simon,

excellent! I didn't figure out how to change the whole line at a time but of course with a repeat...

So when I want to move the green line to the next line (line 2) how do I reset line 1 as it was before I colored it? I could of course just set the opaque to false but the the background color is still green if it is set to true later on.

Another issue I noticed is now when the background is green it is very hard to see when that line is hilited, is it possible to change the opacity of the green to be a bit tranparent? That would make it easier to see the hilited area.

Thanks alot so far!!!

Nicke

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

Re: Change datagrid backgroundcolor for a row from code

Post by Simon » Sat May 10, 2014 9:35 am

how do I reset line 1 as it was before I colored it?
Just this seems to work
dispatch "ResetList" to group "DG1"
is it possible to change the opacity of the green to be a bit tranparent?
I don't think so, I think you have to just select a lighter color
set the backgroundColor of field ("Col" && x && "0002") of grp "DG1" to "148,254,190"

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

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”