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

grid in vfp

Status
Not open for further replies.

ivatanakoo

IS-IT--Management
Oct 9, 2014
23
PH
SELECT item_table
LOCATE FOR status = "For Disposal"
IF FOUND()
thisform.pgfinventory.page1.grdItem_table.BackColor=rgb(159,255,230)
ELSE
endif

i want to change the backcolor of a record with a value of "For Disposal" in the status field
but it just change the back color of all the record
is there something wrong here?
 
Generally in order to selectively change a Grid color you would use the DynamicBackColor property for each of the Grid Row's column's that you want to change.

For example if you wanted to change the row color you might put this in the property for desired Grid Column DynamicBackColor.
IIF(Item_Table.ForDisposal,RGB(255,255,0),RGB(255,255,255))

Note - this would need to be individually put into each and every Grid Column's property that you wished to change.

Also, as with all IIF() functions, you can change the initial expression as needed.

it just change the back color of all the record is there something wrong here

I am guessing that your ForDisposal value is set TRUE for all records and that perhaps you need to have another variable value included in your IIF() expression.

Good Luck,
JRB-Bldr

 
The backcolor of the grid is the overall grid backcolor, not for the current row only, there is no such row property besides the highlighting of selected rows.
The grid also is not having a cell object per row and column. Even the backcolor of a grid.column.text1 textbox would determine the backcolor of a whole column.

Why? Take a look at the grid object model. You have the grid, if you define a columncount it get's column1, column2, etc. sub objects. The column objects each have a header object and a text1 textbox control. One textbox for all the rows. So the grid only has objects for a single row and to display N rows, these controls are painted many times while scanning through the data.

To have different controls and looks per row the columns have dynamicXYZ properties, dynamiccurrentcontrol, dynamicbackcolor, to name just two.
While a grid paints a row these dynamic properties are evaluated.

What you need therefore is grid.SetAll("dynamicbackcolor","=IIF(status='For Disposal',Rgb(159,255,230),Rgb(255,255,255))","column")

That will be evaluated for each row and since you surely want the whole row colored and not just one column, you need to set the dynamicbackcolor of all columns to get the row colored. Sounds insane, but it works.

In the long run you might want different colors for different states, then just set the second parameter of that SetAll call to "=this.rowcolor()" and define a grid method rowcolor, which has to return a color RGB(r,g,b) value. The method will be called for each displayed row so you don't have to locate a row, you simply can access the current records fields, like status. So you'd have code like this in that method:

Code:
Local lnRowColor
Do Case 
   Case status = 'For Disposal'
      lnRowColor =  RGB(159,255,230)
   Case status = 'another status'
      lnRowColor =  RGB(192,192,192) 
   Otherwise
      lnRowColor =  RGB(255,255,255) 
Endcase
Return lnRowColor

Bye, Olaf.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top