Page 1 of 1

Color in DataGrids

Posted: Mon Feb 01, 2010 12:08 am
by lohill
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

Re: Color in DataGrids

Posted: Mon Feb 01, 2010 12:45 am
by sturgis

Re: Color in DataGrids

Posted: Mon Feb 01, 2010 1:28 am
by lohill
Thanks sturgis. That should get me started.

Regards,
Larry

Re: Color in DataGrids

Posted: Mon Feb 01, 2010 9:01 pm
by lohill
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:

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

Re: Color in DataGrids

Posted: Mon Feb 01, 2010 10:27 pm
by sturgis
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.

Re: Color in DataGrids

Posted: Tue Feb 02, 2010 1:57 am
by lohill
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

Re: Color in DataGrids

Posted: Tue Feb 02, 2010 5:50 pm
by trevordevore
am still not getting any color
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.

See the lesson on colorizing lines for a good approach:

How Can I Colorize Individual Lines in a Table?
I assume I make this button invisible and part of the background so that this works on all cards
Yes, you can hide the button.
When you do that it appears that you can create a special script for any of the columns you want
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.
I tried to delete them manually and ended up clobbering my stack
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.

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.

Re: Color in DataGrids

Posted: Tue Feb 02, 2010 6:52 pm
by lohill
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.
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.
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.

Regards,
Larry

Re: Color in DataGrids

Posted: Wed Feb 03, 2010 1:11 am
by sturgis
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

Re: Color in DataGrids

Posted: Wed Feb 03, 2010 5:19 pm
by trevordevore
No worries Mike :-)

Re: Color in DataGrids

Posted: Fri Feb 05, 2010 10:37 pm
by ecflyer
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:

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
Thanks again,
E

Re: Color in DataGrids

Posted: Sat Feb 06, 2010 2:21 am
by trevordevore
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.

Re: Color in DataGrids

Posted: Sat Feb 06, 2010 7:17 am
by ecflyer
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