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

How change color of Grid Row when selecting?

Status
Not open for further replies.

warik

Programmer
Jun 28, 2002
169
ID
Dear all,

How to change grid row color when I press one column of record?

Usualy, it only block with bold line for record (row) selected.

What I need is if I press (Click Procedure) of that record, the row color (record selected) will be change to color, and when I press the other record, the row color of last record will be change to color. The old will be back to white (default) again.

Thank you in advance.
 
If you're running VFP8.0, this is very straightforward. Set the grid's HighlightStyle property to 1 or 2. 1 removes the highlight when the grid loses focus. 2 Leaves the highlight there.

If you're using VFP < 8, then you can add the following to a grid subclass:

New Property:
nRecordNumber

Init:
Code:
this.nRecordNumber = recno()
this.setall(&quot;DynamicBackColor&quot;, &quot;iif(recno() = this.nRecordNumber, EVAL('RGB(' + SUBSTR(RGBSCHEME(15, 6), AT(',', RGBSCHEME(15, 6), 3) + 1)), EVAL('RGB(' + SUBSTR(RGBSCHEME(15, 2), AT(',', RGBSCHEME(15, 2), 3) + 1)))&quot;, &quot;Column&quot;)
this.setall(&quot;DynamicForeColor&quot;, &quot;iif(recno() = this.nRecordNumber, EVAL(LEFT(RGBSCHEME(15, 6), AT(',', RGBSCHEME(15, 6), 3) - 1) + ')'), EVAL(LEFT(RGBSCHEME(15, 2), AT(',', RGBSCHEME(15, 2), 3) - 1) + ')'))&quot;, &quot;Column&quot;)
this.setall(&quot;DynamicFontBold&quot;, &quot;recno() = this.nRecordNumber&quot;, &quot;Column&quot;)

AfterRowColChange:
Code:
this.nRecordNumber = recno()
this.refresh

Cheers,
Andrew


Andrew Coates
OzFox 2003 Australia's VFP Conference -- ------
DISCLOSURE
We are the Australasian Distributor for the Hentzenwerke Series of Books. (By the same token, I really do think they're the best printed VFP resource out there -- that's why we sell them)
 
Andrew, thank you for your reply. I use VFP 5.0 and I still don't understand how to add New Property ad Grid Subclass?

You write:
If you're using VFP < 8, then you can add the following to a grid subclass:

New Property:
nRecordNumber
 
- Type the following in the command window:
Code:
create classlib myclasslib
create class
- Type a name for your new class (e.g. MyGrid)
- Choose Grid from the drop-down
- Choose your new classlib (MyClassLib) as the class library
- Click OK (I think -- I have't got VFP 5 loaded anywhere at the moment)

Now you have a subclass of the Grid class. You can choose New Property from the Class menu and add the nRecordNumber property.

Add the code from my first post to the Init and AfterRowColChange events.

Press CTRL+W to save and close your new class.

Now use this class for your grids and the current row will be highlighted.

I do suggest that you get a book like Whil Hentzen's Fundamentals ( and go through some of this OOP stuff.

Cheers,

Andrew


Andrew Coates
OzFox 2003 Australia's VFP Conference -- ------
DISCLOSURE
We are the Australasian Distributor for the Hentzenwerke Series of Books. (By the same token, I really do think they're the best printed VFP resource out there -- that's why we sell them)
 
Yes Andrew it work now. [thumbsup]
Thank you very much for your help and your suggestion.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top