Color in DataGrids
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Color in DataGrids
Is it possible to control the color of individual cells in a datagrid? Alternately, is it possible to control the text color in individual cells of a datagrid? For example could all negative numbers in a grid show up as red text? If it is possible, can some one point me to the documentation?
Thanks in advance,
Larry
Thanks in advance,
Larry
Re: Color in DataGrids
Check here.
http://revolution.screenstepslive.com/s ... to-a-Cell-
And here is the manual root link. http://revolution.screenstepslive.com/s ... s/datagrid
http://revolution.screenstepslive.com/s ... to-a-Cell-
And here is the manual root link. http://revolution.screenstepslive.com/s ... s/datagrid
Re: Color in DataGrids
Thanks sturgis. That should get me started.
Regards,
Larry
Regards,
Larry
Re: Color in DataGrids
Hi Sturgis,
I have made an attempt to get one of the columns of my DataGrid to show red, green or black text depending on the value that will go in that cell. I have made a 'My Default Column Behavior' button and modified the code for the FillInData event to look like the following:
According to the Dictionary, 'foregroundcolor' is a synonym for textColor. I have tried the 'set text' both before and after the 'Switch' and am still not getting any color. I even tried 'set the foreGroundColor of the text me to "green"" and that just hung up without getting to the column. I have stepped through in debug mode and my 'switch' seems to work fine, just no color change. The only conclusion I can come to is that foreGroundColor is not the correct attribute.
Also, since I have multiple cards that use this same grid and they all have the same behavior, I assume I make this button invisible and part of the background so that this works on all cards.
Any suggestions would be appreciated.
Thanks,
Larry
I have made an attempt to get one of the columns of my DataGrid to show red, green or black text depending on the value that will go in that cell. I have made a 'My Default Column Behavior' button and modified the code for the FillInData event to look like the following:
Code: Select all
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.
put the dgColumn of me into tCol
switch tCol
case "Daily Gain"
if pData > 0 then
set the foreGroundColor of me to "green"
else
If pData < 0 then
set the foreGroundColor of me to "red"
else
set the foreGroundColor of me to "black"
end if
end if
end switch
set the text of the long id of me to pData ## temp workaround for
end FillInData
Also, since I have multiple cards that use this same grid and they all have the same behavior, I assume I make this button invisible and part of the background so that this works on all cards.
Any suggestions would be appreciated.
Thanks,
Larry
Re: Color in DataGrids
Well, I can't get it to work either. Have tried all kinds of things, but can't get the color to set. Nor the background color.
On your question of setting, the behavior button to be a background group so its available on all cards, that shouldn't be necessary because they behavior is set with the long id of the button, so it can be found from anywhere. Once you figure out why this isn't working, hide it.
Wish I could help but unfortunately lately, my abilities in this area are going backwards.
On your question of setting, the behavior button to be a background group so its available on all cards, that shouldn't be necessary because they behavior is set with the long id of the button, so it can be found from anywhere. Once you figure out why this isn't working, hide it.
Wish I could help but unfortunately lately, my abilities in this area are going backwards.
Re: Color in DataGrids
Sturgis,
I also noted in my explorations that the script in the button 'My Default Column Behavior' is basically (until I modified it) like the scrips that come up when you are in the Inspector for the DataGrid and take the choice in Columns for Column Behavior at the bottom of the window. When you do that it appears that you can create a special script for any of the columns you want. The script that comes up seems similar to the my 'default behavior' script and I guess any changes made there would apply to just that one column. That way you wouldn't need the 'switch'. If they are both present would one of them take precedence over the the other?
I also noticed that those scripts produce buttons on one of the dataGrid cards. I'm not sure how to remove those gracefully. There didn't seem to be any choice in the Inspector that created them. I tried to delete them manually and ended up clobbering my stack. Not too big a deal because I am doing better at saving old versions to revert to.
Maybe Trevor will weigh in on this subject. In the meantime, I have other things that need exploring. Do you have any suggestions for formatting numbers when they get put in a grid?
Thanks,
Larry
I also noted in my explorations that the script in the button 'My Default Column Behavior' is basically (until I modified it) like the scrips that come up when you are in the Inspector for the DataGrid and take the choice in Columns for Column Behavior at the bottom of the window. When you do that it appears that you can create a special script for any of the columns you want. The script that comes up seems similar to the my 'default behavior' script and I guess any changes made there would apply to just that one column. That way you wouldn't need the 'switch'. If they are both present would one of them take precedence over the the other?
I also noticed that those scripts produce buttons on one of the dataGrid cards. I'm not sure how to remove those gracefully. There didn't seem to be any choice in the Inspector that created them. I tried to delete them manually and ended up clobbering my stack. Not too big a deal because I am doing better at saving old versions to revert to.
Maybe Trevor will weigh in on this subject. In the meantime, I have other things that need exploring. Do you have any suggestions for formatting numbers when they get put in a grid?
Thanks,
Larry
-
- VIP Livecode Opensource Backer
- Posts: 1005
- Joined: Sat Apr 08, 2006 3:06 pm
- Contact:
Re: Color in DataGrids
Modify the dgHilite setprop in the behavior script. The default script sets the foregroundColor to empty or the hilite color based on the boolean passed into the setprop. Basically your color is being erased.am still not getting any color
See the lesson on colorizing lines for a good approach:
How Can I Colorize Individual Lines in a Table?
Yes, you can hide the button.I assume I make this button invisible and part of the background so that this works on all cards
Yes, you can customize the script of each column individually if you want. When you click that little + button for a column the Revolution IDE creates a control for the column and a new button for the columns behavior. This will override the "default column behavior" that applies to the rest of the cells in your table.When you do that it appears that you can create a special script for any of the columns you want
Deleting the behavior button for a column shouldn't cause any physical harm but it will keep your column from rendering properly since there is no longer a valid behavior associated with it.I tried to delete them manually and ended up clobbering my stack
On the Row template card just select the control named after your column and updates it's behavior property in the Revolution property inspector. You will need to set the behavior to whatever button has the behavior you want to use.
Or you can just delete the control named after the column entirely and refresh the Data Grid. This causes the Data Grid to revert to the default cell controls/behavior.
Trevor DeVore
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
Re: Color in DataGrids
Thanks Trevor,
That did it. I just commented out the line in setProp that said 'set the foregroundcolor of me to empty' and now my colors are showing nicely.
Regards,
Larry
That did it. I just commented out the line in setProp that said 'set the foregroundcolor of me to empty' and now my colors are showing nicely.
It is good to remember this because it is very easy to click those plus buttons in the inspector just to see what they do and then not realize that you may be overriding some critical scripting.Yes, you can customize the script of each column individually if you want. When you click that little + button for a column the Revolution IDE creates a control for the column and a new button for the columns behavior. This will override the "default column behavior" that applies to the rest of the cells in your table.
Regards,
Larry
Re: Color in DataGrids
Thanks Trevor, and sorry I couldn't help Larry. Thinkin its time for me to fall off the earth again for a while, thx all for the continued help, and welcome!
Take care all,
Mike
Take care all,
Mike
-
- VIP Livecode Opensource Backer
- Posts: 1005
- Joined: Sat Apr 08, 2006 3:06 pm
- Contact:
Re: Color in DataGrids
No worries Mike 

Trevor DeVore
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
Re: Color in DataGrids
I created a custom behavior button and went through the example in the DataGrid manual for truncated the data in a cell. I can get the data to truncate, but only when I attempt to resize the column even though the column starts out to small for the sentence. And then when I refresh the DG, the truncate "..." goes away. Thanks.
Here's what's in my button:
Thanks again,
E
Here's what's in my button:
Code: Select all
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 the long ID of me to pData ## temp workaround for
set the uText of me to pData
set the text of me to the uText of me
end FillInData
on LayoutControl pControlRect
-- A default column is just a field. Nothing to change here.
set the text of me to the uText of me
TruncateTail the short ID of me, "..."
end LayoutControl
E
-
- VIP Livecode Opensource Backer
- Posts: 1005
- Joined: Sat Apr 08, 2006 3:06 pm
- Contact:
Re: Color in DataGrids
You are missing the call to TruncateTail in FillInData which the example in the manual has. Try adding it and then it should work.
BTW, since this is a different topic than the original thread you should start a new thread.
BTW, since this is a different topic than the original thread you should start a new thread.
Trevor DeVore
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
ScreenSteps - https://www.screensteps.com
LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder
Re: Color in DataGrids
thanks as always Trevor, I had it in there originally, but deleted by accident when I deleted a switch-case script I had in there. I thought the topic was similar, being a customize column question, but I will watch the topics in the future.
Thanks,
E
Thanks,
E