CellSelected Property

See AlsoIHZB8Z              ExampleK3ZTMT>Low

Applies To



Determines whether the cell specified by the Col and RowL43H93 properties (the active cell) is within the grid's selected region.  Not available at design time; read-only at run time.




The CellSelected property settings are:

Setting         Description


True             The specified cell is within the selected area.

False             The specified cell is not within the selected area.



This property allows you to determine whether the user has selected a specific cell or a specific range of cells.

At run time, the user can select a range of cells by clicking a cell and then dragging the mouse or by pressing the Shift key and using the arrow keys.

Use the SelEndCol, SelStartCol, SelEndRow, SelStartRow1Q7SBUK properties to determine the selected region.  Use the Col and Row properties to determine the active cell.

Data Type

IntegerDOKXHY (Boolean)

See Also


Col, Row PropertiesL43H93

RowColChange Event1P1L2J7

SelChange Event41BQVWT

SelEndCol, SelStartCol, SelEndRow, SelStartRow Properties1Q7SBUK


Programmer's Guide:

Chapter 3, "Creating and Using Controls"

CellSelected Example

The example selects a cell at random and tells you whether it is selected or not when the grid is clicked.  To try this example, use the Add File command on the File menu to add GRID.VBX to the project, paste the code into the Declarations section of a new form, and then draw a grid and a label.  For the label, set AutoSize to True.  Press F5 to run the program.

Dim TRow As Integer

Dim TCol As Integer


Sub Form_Load ()

   Grid1.Rows = 8    ' Set rows and columns.

   Grid1.Cols = 5


   ' Choose a cell at random.

   TRow = Int(Rnd * (Grid1.Rows - 1)) + 1

   TCol = Int(Rnd * (Grid1.Cols - 1)) + 1

End Sub


Sub Grid1_Click ()

   Grid1.Row = TRow

   Grid1.Col = TCol

   If Grid1.CellSelected Then

      Label1.Caption = "You found it!"


      Label1.Caption = "Not yet. Try again."

   End If

End Sub