Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Colour of cells in a grid 1

Status
Not open for further replies.
Sure,
Just check DynamicBackColor and DynamicForeColor properties of the Column Object.
Also check "Dynamically format grid columns" in Solution Samples to see how it could be done.

In General you could use this:
Code:
thisform.Grid1.Column1.DynamicBackColor = "IIF(SomeCondition,RGB(color you want when SomeCondition is True),RGB(color you want when SomeCondition is False))"

If the conditions are many you could use a method in the form where you could return the desired color:
Code:
thisform.Grid1.Column1.DynamicBackColor = "thisform.GetColor()"

*** thisform.GetColor method:
LOCAL liColor
DO CASE
   CASE Condition1
        liColor = RGB(....) && Some color
   CASE Condition2
        liColor = RGB(....) &&  color2
   CASE Condition3
        liColor = RGB(....) && color 3
.....
   CASE ConditionN
        liColor = RGB(....) && Color N
OTHERWISE
        liColor = thisform.Grid1.Column1.BackColor
ENDCASE
RETURN liColor

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Thanks Boris
I am calling the colouring routine from the InteractiveChangeEvent of a check box in a grid cell. There is a step lag between the keypress and the color being shown.
I tried a form refresh but that just stops the form from working.

Any way round the lag?

Keith
 
Keith,

If I may jump in ....

The problem is that, at the time that the InteractiveChange executes, the underlying cursor hasn't yet received the value from the checkbox, so the DynamicBackColor won't react.

To fix it, do this (in the InteractiveChange):

Code:
WITH TheGrid
  .Refresh 
  .ActivateCell(.ActiveRow, .ActiveColumn + 1)
  .ActivateCell(.ActiveRow, .ActiveColumn - 1)
ENDWITH

This forces focus off the checkbox and then back again, which will allow the cursor to be updated and the colour to take effect.

If the checkbox happens to be in the right-most row, then you should reverse the +1 and -1.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Sorry Mike but that has made no difference.
I am not forced to use the interactive change if there is a better way of doing it.
This is a mailer which is being added on to a existing app.
I am once again into the VFP cycle where I spend half a day writing the code and then an absolute age juggling the objects around to make them play nice.

Is this normal?



Keith
 
Try with and old brute force method:
Code:
** IAC method
this.Value = this.Value
thisform.Grid1.Refresh()
that will force underlying cursor to be updated

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Because it forces update to Underlying cursor field to be updated before Valid event being executed.

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
I place the following statement into the Refresh methjod of the grid. It just works.

this.setall("dynamicbackcolor", "grid_colour()" , "column")


And the grid_colour() function can apply any logic that you require to determine the colour. Like the example provided by bborissov

Hope that helps.

Paul.
 
Paul,

I place the following statement into the Refresh methjod of the grid.

Yes, that will work, but it would be more efficient to place the code in the Init method. You only need to do it once, and it's generally a good idea to keep the Refresh as light as possible.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top