How to Highlight an Entire Row of Cells in the Grid Control

Last reviewed: June 21, 1995
Article ID: Q113589
The information in this article applies to:

- Microsoft Visual Basic programming system for Windows,

  versions 2.0 and 3.0

SUMMARY

The sample code in this article demonstrates how to highlight an entire row of cells for the Grid control including the cell that you select. This sample uses the following properties: SelStartRow, SelStartCol, SelEndRow, and SelEndCol. In addition to highlighting the entire row, the sample code also highlights the cell you clicked.

MORE INFORMATION

Steps to Highlight an Entire Row of Cells in a Grid

  1. Start a new project in Visual Basic. Form1 is created by default.

  2. Add one Grid control (Grid1) to Form1.

  3. Set both the Cols and Rows properties of the Grid1 control to 8.

  4. Place the following code in the Grid1 Click event procedure of Form1:

       Sub Grid1_Click ()
          ' Following statements highlight all cells except clicked cell:
          If grid1.Row > 0 Then
             grid1.SelStartRow = grid1.Row
             grid1.SelEndRow = grid1.Row
             grid1.SelStartCol = grid1.fixedcols ' Start after fixed columns.
             grid1.SelEndCol = grid1.cols - 1    ' end at the last columns.
             ' Rows & columns are numbered starting at 0,
             ' so the last column is 1 less than the Cols property
          End If
    
          ' Following two lines help highlight the individual cell, so change
          ' these lines to comments to see the difference:
          grid1.Row = 0
          grid1.Col = 0
       End Sub
    
    

  5. From the Run menu, choose Start (ALT, R, S), or press the F5 key to run the program. Click a cell in Grid1.


Additional reference words: 1.00 2.00 3.00
KBCategory: kbprg kbcode
KBSubcategory: APrgDataAcc


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 21, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.