Knowledge Base

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

Article ID: 113589

Article Last Modified on 10/28/2003


APPLIES TO


This article was previously published under Q113589

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 query words: 1.00 2.00 3.00

Keywords: KB113589