Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Cetin Basoz
  Where is Cetin Basoz?
 Izmir
 Turkey
 Cetin Basoz
 To: Mark LaBarre
  Where is Mark LaBarre?
 Rockville
 Maryland - United States
 Mark LaBarre
 Tags
Subject: RE: Highlighting Grid Row based on filter
Thread ID: 344984 Message ID: 345034 # Views: 41 # Ratings: 1
Version: Visual FoxPro 9 Category: Grids
Date: Thursday, May 17, 2012 2:32:16 PM         
   


> I've read about how to highlight a grid row based on the mouse-selected row/cell. What I'm wondering is whether there's some way to change backcolor or change the font to bold, based on a filter instead of on a click event.
>
> What I'm doing is selecting an auto part ID code based on a combo of year / make / model / engine size. Once I have the ID code, I use it to display the part description and price from a table of unique parts IDs. I also link it by part ID to a child table for all years / makes / models / engine sizes of cars that take that part ID. Then these records are displayed in the grid in question. There can be 15 or more child records for a single specific part ID.
>
> I want to make the correct row stand out from the others, but am not sure how to accomplish that. The child table has the exact same field names and values that I plug into the filter string, so I could use the identical string to identify the row I want to highlight. But I'm not sure how to get from identifying the correct row, to highlighting just that row without any user input -- just based on the filter string.

To expand what Stefan said with a code sample:

Public oForm
oForm = Createobject('myForm')
oForm.Show

Define Class myForm As Form
  DataSession = 2
  Height=400
  Width=400

  Add Object myGrid As Grid With ;
    RecordSource='Orders',  Height=400,  Width=400,Anchor=15, ReadOnly=.T.

  Procedure Load
    Use (_samples+'data\orders')
  Endproc

  Procedure Init
    This.myGrid.SetAll('DynamicBackColor', '(thisform.ColorMe(Orders.Emp_id, .F.))')
    This.myGrid.SetAll('DynamicForeColor', '(thisform.ColorMe(Orders.Emp_id, .T.))')
  Endproc

  Procedure ColorMe(tcValue, tlForeColor)
    Local lnBackColor, lnForeColor
    lnBackColor = Bitand( Val(Sys(2007,m.tcValue,1,1)), 0x00FFFFFF )
    If !m.tlForeColor
      Return m.lnBackColor
    Endif

    Local lnRed, lnGreen, lnBlue,lnAlpha
    lnRed = Bitand(Bitrshift(m.lnBackColor,0),0xFF)
    lnGreen = Bitand(Bitrshift(m.lnBackColor,8),0xFF)
    lnBlue = Bitand(Bitrshift(m.lnBackColor,16),0xFF)
    lnAlpha = (Max(m.lnRed,m.lnGreen,m.lnBlue)+Min(m.lnRed,m.lnGreen,m.lnBlue))/2

    Return Iif(m.lnAlpha < 0x80, 0xFFFFFF, 0)
  Endproc
Enddefine


PS: SetAll sets the expression for all columns. Instead you might use different expression for individual columns and achieve 'cell level' coloring despite 'row level'. Check:

https://www.foxite.com/archives/0000344908.htm



Cetin Basoz

.Net has got better.Think about moving - check my blog:
My Blog
Blog (mirror) - sounds to be down


Support Wikipedia

ENTIRE THREAD

Highlighting Grid Row based on filter Posted by Mark LaBarre @ 5/16/2012 6:44:18 PM
RE: Highlighting Grid Row based on filter Posted by Stefan Wuebbe @ 5/16/2012 8:12:24 PM
RE: Highlighting Grid Row based on filter Posted by Cetin Basoz @ 5/17/2012 2:32:16 PM