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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conditional formatting in a V F P grid 1

Status
Not open for further replies.

David Higgs

Programmer
May 6, 2012
392
GB
I've managed to get my Grid Rows in alternate colours by placing the following in "Grid INIT":-

this.SetAll("DynamicBackColor", "IIF(alt_col % 2 = 0,RGB(255,255,255), RGB(204,255,204))", "Column") && Alternate Green and White records

I would like to take this a stage further and change the "Row (back or fore) Colour" to Red for certain conditions.
ie if Field wab_net_list.userstatus ="A" change colour to red

I have tried a few examples with no success; any help would be most appreciated.

Regards,
David
 
Hi,

You may want to try this

This.SetAll("DynamicBackColor", "IIF(tblTable.UserStatus = [A], RGB(...), RGB(...))", "Column")

hth

MK
 
David,

MK has given you a good answer. For some more general information, with further examples, take a look at:

Conditional formatting in a Visual FoxPro grid

A further note: Given that you are already using DynamicBackColor to highlight alternate rows, I suggest you use DaynamicForeColor to indicate the UserStatus.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thank you both for your replies.

MK, I will try your advice, much appreciated.

Mike, I did wonder about which to use (fore/back colour). It's not a problem using fore colour so long as the row can be recognised visually.

I hope you guys don't mind me asking what may appear to be simple questions, we all have to start somewhere!

Regards,
David
 
No, of course we don't mind "simple" questions. What might appear simple to some could be difficult to others.

Regarding the choice of ForeColor and BackColor, you might always want to consider DynamicFontBold for highlighting your Status A cases. Although it's matter of taste, I find that an occasional bold row stands out better than, say, a red one.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
MK, that worked a treat!!

Mike, Thank you for the link to Hex Central, I'll try and digest it all!

Regards,
David
 
With reference to the following:=

this.SetAll("DynamicBackColor", "IIF(alt_col % 2 = 0,RGB(255,255,255), RGB(204,255,204))", "Column")

1:
what does the "%" and the "2" mean?​
2:
What does the "column" statement mean? Can "Row" be substituted?​



Regards,
David
 
what does the "%" and the "2" mean?

It means modulus 2, that is, the remainder that is left after dividing by two. It's a way of testing whether a number is odd or even. The point is that you want odd rows to have a certain BackColor, and even rows to have a different BackColor.

What does the "column" statement mean? Can "Row" be substituted?

It means the SetAll applies to all the columns in the grid, and not to any the other control that might be in the grid (see the Help for SetAll for some other examples). You can't use "Row" here because rows are not objects. The grid is essentially a collection of columns; it's not a collection of rows (for reasons that are too arcane to worry about).

Mike





__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike,
Thank you for your explanation, I will indeed take a look at the VFP Help file. I'm really enjoying VFP since upgrading to Ver 9 and joining this forum.

Regards,
David
 
Ok, so now that I've moved on from using "BROWSE" I need a little guidance on how to proceed with my new "GRID" Form.

I previously used the following in a command button:-

BROWSE FONT 'Bookman Old Style',12 FOR worked ="Y" .AND. b_SERIES = 1

I now use the command button to call a form with a grid which displays the entire database, how do I recreate the above in my grid?


Regards,
David
 
David,

You might get a better response if you start a new thread for this question. It has got nothing to do with conditional formatting. There's a lot to know about grids, and a new thread will give us plenty of scope for helping you.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Ok Mike, sorry about that, I was undecided about starting a new topic.

Anyway just to update, I solved my problem by using the "SET Filter" Command.


Regards,
David
 
In regard of the font, you'll need a SetAll() to set all controls fontname and fontsize properties,

ie Grid.SetAll("Fontname","Bookman Old Style") and Grid.SetAll("Fontsize",12), this will set whatever inner objects of the grid, that have these properties.
You can also set the font styles per column.

In response to your earlier question and Mikes answer about rows: There are no row objects, but of course there are rows and each row will be formatted different via Dynamic properties, as you know for the color, there are further DynamicXYZ properties, including Fontsize and -name, also Fontbold, Italic, Outline, Shadow. And you can call a method with the expression, not just directly embed an IIF statement, the only thing the method needs to return is the correct type and value for the property, eg a RGB value for the Dynmic...color properties. The method itself can influence even more things, eg set the Picture of an image control or whatever you need per row.

Bye, Olaf.
 
I would use a function rather than any complex IIF()

Code:
this.SetAll("DynamicBackColor", "MyBGColor(alt_col)", "Column")

Function MyBGColor
  Parameter m.ControlColumn
  Private m.ControlColum,m.RGBValue
  m.RGBValue = RGB(255,255,255)
  if m.ControlColumn % 2 <> 0
    m.RGBValue = RGB(204,255,204)
  endif
  return(m.RGBValue)


Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are not good for you.
 
Many thanks for all the help and advice; should keep me quiet for a while!

Regards,
David
 
Extending Griffs idea, you could of course combine the alternate coloring with highlighting, there are 4 color mixes: dark and light rows and dark and light red for highlighted rows. In one place I even do this with three yes/no flags resulting in 8 different colors. It looks nice that way. Surely sommething you wouldn't want to do with IIF, even not with ICASE.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top