Numbers with red text in DataGrid cell

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

Numbers with red text in DataGrid cell

Post by lohill » Mon Oct 06, 2014 11:08 pm

This has me stumped now but I have done it before with code very similar to what I show below. Can anyone spot why this is not working?

I have a datagrid with 33 columns where the even numbered rows contain basically just text while the odd rows contain mostly 'numeric' values even though the column itself is set for text format. Under certain conditions I want the 'numeric' text to show up red while all the other text is black. I am using the FillnData routine that is in my button called My Default Column Behavior to accomplish this. Here is partial code for that button:

Code: Select all

   -- 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
   global gLiquidity
   put the dgColumn of me into tCol
   If tCol="Pick30" then
      beep
   end if
   if offset("Pick",tCol)>0 then
      put "Pick" into tCol
   end if
   switch tCol
      case "Pick"
         if isNumber(pData) then
            set the numberFormat to "#.0000"
            put pData*1 into pData
            if pData > gLiquidity then
               set the foreGroundColor of  me to "red"
            end if
         end if
         break
      case "Average"
         set the numberFormat to "#.0000"
         put pData*1 into pData
         if pData > gLiquidity then
            set the foreGroundColor of  me to "red"
         end if
         break
   end switch
   set the text of the long ID of me to pData ## temp workaround for
end FillInData
The columns in question are called Pick1,Pick2, Pick3, ... Pick30 and there also ia a column called Average that may need to me made red. There is a global variable called Liquidity that is compared to the 'numbers' in those columns that determines when the I want the color red. In the code I have an if condition (would not normally be included) that lets me insert a breakpoint to stop when I get to the last column. When I get to that point, the cells that are supposed to contain red text do contain red text. When I step slowly and finish the FillnData routine the next step puts me back in the FillnData routine for the next row od data but the line I just finished is now all black.

Is there some datagrid setting I am missing? Why is it changing back. The other situations where I have used FillnData to change the color of the text have not involved a global variable nor the alternating rows.

Thanks for any light you can shed on this,
Larry

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Numbers with red text in DataGrid cell

Post by dunbarx » Mon Oct 06, 2014 11:45 pm

Hi.

Have your tried to refresh the DG? This is not automatic, and especially not after changes are made under script control:

dispatch "resetList" to group "yourDataGrid"

Craig Newman

lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

Re: Numbers with red text in DataGrid cell

Post by lohill » Tue Oct 07, 2014 1:11 am

Hi Craig,

That didn't do the trick. I tried both your 'dispatch' statement and a manual refresh datagrid and I still get all black text when everything is done.

Any other possibilities?

Larry

keithglong
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 348
Joined: Sun Jul 03, 2011 2:04 am

Re: Numbers with red text in DataGrid cell

Post by keithglong » Tue Oct 07, 2014 7:06 am

Hi,

It might be helpful if you could post a sample stack for folks to look at...

Cheers,

- Boo

lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

Re: Numbers with red text in DataGrid cell

Post by lohill » Tue Oct 07, 2014 6:35 pm

Craig,

I found the problem. By setting more breakpoints in the entire script for 'My Default Column Behavior' button, I discovered that after getting to the end of the line of my data and before going back to FillnData , the routine setProp dgHilite was executed. I found that by commenting out the step of that script shown in the code below I could get the red to stay.

Code: Select all

setprop dgHilite pBoolean
    -- This custom property is set when the highlight of your column template has
    -- changed. You only add script here if you want to customize the highlight.
    if pBoolean then
        set the foregroundColor of me to the dgProp["hilited text color"] of the dgControl of me
    else
        --set the foregroundColor of me to empty
    end if
end dgHilite
AFAIK that is not even a routine I had messed with.

Thanks, Larry

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Numbers with red text in DataGrid cell

Post by dunbarx » Tue Oct 07, 2014 7:31 pm

Larry.

Great detective work. DataGrids are complex, all right.

Craig

Post Reply