Change datagrid backgroundcolor for a row from code [SOLVED]
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Change datagrid backgroundcolor for a row from code [SOLVED]
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
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.
Re: Change datagrid backgroundcolor for a row from code
Ok, I figured out how to change the hilited row...
Now I just need help with the backgroundcolor
Code: Select all
set the dgHilitedIndex of group "dataGrid" to 2
-
- VIP Livecode Opensource Backer
- Posts: 9670
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Change datagrid backgroundcolor for a row from code
Hi.
Make a DG (hopefully this will be "grp 1"). Put several lines of data into it.
try this in a button somewhere:
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
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
Craig Newman
Re: Change datagrid backgroundcolor for a row from code
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
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
Re: Change datagrid backgroundcolor for a row from code
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
BR Nicke
-
- VIP Livecode Opensource Backer
- Posts: 9670
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Change datagrid backgroundcolor for a row from code
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:
What am I missing? Line 1 maintains focus on the DG. This can wander if one is not careful.
Craig
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
Craig
Re: Change datagrid backgroundcolor for a row from code
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:
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
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
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
-
- 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
Hi Nicke,
Along with Craig's stuff, put this into the DG1 script:
Happens so fast you wont see it.
Simon
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
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: Change datagrid backgroundcolor for a row from code
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
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
-
- 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
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
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!
Re: Change datagrid backgroundcolor for a row from code
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
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
-
- 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
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
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!
-
- 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
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
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: Change datagrid backgroundcolor for a row from code
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
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
-
- 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
Just this seems to workhow do I reset line 1 as it was before I colored it?
dispatch "ResetList" to group "DG1"
I don't think so, I think you have to just select a lighter coloris it possible to change the opacity of the green to be a bit tranparent?
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!