See Also Example
Applies To
Grid.
Description
Occurs when the currently active cell changes to a different cell.
Syntax
Sub grid_RowColChange ( )
Remarks
This event occurs whenever the user clicks a cell other than the selected cell or when you programmatically change the active cell within a selection.
You can trigger this event in code by changing the current cell using the Col and Row
The SelChange
Help:
SelChange Event
Programmer's Guide:
Chapter 3, "Creating and Using Controls"
RowColChange, SelChange Events Example
Col, Row; Cols, Rows; SelEndCol, SelEndRow, SelStartCol, SelStartRow Properties Example
The example displays the location of the active cell and the range of the selection as a user selects cells or ranges. Notice that when selecting a range, the active cell does not change. Select a range and then click the form to move the active cell around the perimeter of the selection. Notice that the selected range does not change.
To try this example, create a new project, add GRID.VBX using the Add File command on the File menu, and then draw a grid and two labels. Copy the code into the Declarations section and press F5 to run the program.
Sub Form_Load ()
Grid1.Cols = 6 ' Set columns and rows.
Grid1.Rows = 7
End Sub
Sub Grid1_RowColChange ()
Msg = "Active Cell: " & Chr(64 + Grid1.Col)
Mst = Msg & Grid1.Row
Label1.Caption = Msg
End Sub
Sub Grid1_SelChange ()
Msg = "Selection: " & Chr(64 + Grid1.SelStartCol)
Msg = Msg & Grid1.SelStartRow
Msg = Msg & ":" & Chr(64 + Grid1.SelEndCol)
Msg = Msg & Grid1.SelEndRow
Label2.Caption = Msg
End Sub
Sub Form_Click ()
' This procedure moves the active cell around
' the perimeter of the current selected range
' of cells with each click on the form.
Dim GR, GC As Integer
If Grid1.Row = Grid1.SelStartRow Then
If Grid1.Col = Grid1.SelEndCol Then
GR = 1: GC = 0
Else
GR = 0: GC = 1
End If
ElseIf Grid1.Row = Grid1.SelEndRow Then
If Grid1.Col = Grid1.SelStartCol Then
GR = -1: GC = 0
Else
GR = 0: GC = -1
End If
Else
If Grid1.Col = Grid1.SelStartCol Then
GR = -1: GC = 0
Else
GR = 1: GC = 0
End If
End If
Grid1.Row = Grid1.Row + GR
Grid1.Col = Grid1.Col + GC
End Sub