How To Highlight the Entire Row in Grid When User Clicks

This article was previously published under Q130458
This article has been archived. It is offered "as is" and will no longer be updated.
In FoxPro version 2.x, you can't issue a browse and have the entire rowselected when a user clicks. In Visual FoxPro, however, you can create agrid, and have the entire row selected when a user clicks. This articleshows you how.
NOTE: You can also use this technique to make the current record in thegrid remain highlighted after the focus is set to another object on theform.

Step-by-Step Example

  1. Create a new form by using the Form Designer.
  2. Bring up the Data Environment for the form by choosing Data Environment from the View menu. Select Add to add the customer table located in the C:\VFP\SAMPLES\MAINSAMP\DATA directory into the data environment. Drag the customer table from the data environment, and drop it onto the form to create a grid object.
  3. Place the following code in the grid's INIT event:
       PUBLIC grno   grno = RECNO()   THIS.setall("Dynamicbackcolor", ;        "IIF(RECNO()=grno,RGB(64,128,128),RGB(255,255,255))","Column")								
  4. Place the following code in the grid's AfterRowColChange event:
       LPARAMETERS nColIndex   grno = RECNO()   THIS.Refresh()								
  5. Run the form, and click different rows. You will see the selected row's backcolor is in dark green color.

Article ID: 130458 - Last Review: 02/21/2014 00:27:48 - Revision: 2.2

Microsoft Visual FoxPro 3.0 Standard Edition, Microsoft Visual FoxPro 5.0 Standard Edition, Microsoft Visual FoxPro 6.0 Professional Edition, Microsoft Visual FoxPro 3.0b for Macintosh

  • kbnosurvey kbarchive kbcode kbhowto KB130458