Article ID:qOOP016
Date Revised:October 26, 1997
Keywords:Grid, row highlight
Synopsis:26-Oct-97 Updated Beta release of dfhgrid
See Also:dfhgrid.zip 

Question: How can I highlight the current record in a grid without the runtime performance penalty caused by using the Grid.Column.DynamicForeColor and Grid.Column.DynamicBackColor properties?

Answer: 26-Oct-97 The Grid subclass exposes several new methods to give additional control of the hilighting shape. It also fixes the problems found since the first release.

The classlib attached to this article uses a Shape object that floats over the grid. The shape uses the features of the DrawMode property to allow the shape to "mix" its BackColor with the underlying grid contents graphically. So it works at Windows BitBlt (fancy term for binary ANDs and ORs of 2 graphical areas together) speed. I've found this functionality so useful that I've put all of this into my cGrid class that all other grids are derived from.

To use this grid class and enable the Highlight indicator all you have to do is set mlHighlightRow = .T. in the form designer.

The grid adds the shape object to the grid.parent during the Grid.Init() event. The .Top of the shape is moved with the Grid.RelativeRow property.

By default the shape inverts the grid row using DrawMode 6. So a black text on white cells grid will have a row with white text on black cells. All sorts of combinations are possible using the mnHighlightRowBackColor and mnHighlightRowDrawMode properties of the grid subclass.

The following table shows what happens with mnHighlightRowBackColor = 255,0,0 (red) and grid cells that are black text on white background and the possible mnHighlightRowDrawModes

DrawMode   Appearance of Row
1All black ¹
2Dark cyan on black
3Black on dark cyan
4All dark cyan ¹
5Red on black
6White on black (Default)
7Red on dark cyan
8White on dark cyan
9Black on red
10Dark cyan on red
11Black on white i.e. no difference
12Dark cyan on white
13All red ¹
14White on red
15Red on white
16All white ¹
 
 
¹ The usefulness of these DrawModes
is somewhat limited. *grin*

Some other sample BackColor and DrawModes:

To get black text on a yellow background use 255,255,0 and 9

To get black text on a light green background use 64,255,64 and 9

To get light green text on a black background use 64,255,64 and 5

There is a sample form in the project where you can play with the DrawMode and BackColor properties to see the various effects. The grid uses the home()+"\samples\data\products.dbf" for it's datasource by default, if it's not found you'll be prompted to open a file. It is opened NOUPDATE.

If the grid header and/or rows are resized the highlight may appear to be the wrong size, but I believe this is an artifact of the grid redraw, if the grid is scrolled the row size will once again be in sync with the highlight size.

Also to click with the mouse back into the grid on the active row takes a second click to get into the cell, at this point it's not worth the effort to find the control within the grid that should receive the click.

NOTE: The attached file is stable code but I'm calling this a beta release because I don't have all the documentation done yet.


1