Col, Row Properties Example

This example puts "Here" into the current cell and then changes the active cell to the third cell in the third row and puts "There" into that cell. To try this example, use the Components dialog box to add an MS Flex Grid control to the toolbox (from the Project menu, choose Components, and then check Microsoft Flex Grid Control), and then draw a grid on a new form. To run the program, press F5, and then click the grid.

Private Sub Form_Load ()
   MSFlexGrid1.Rows = 8   ' Set rows and columns.
   MSFlexGrid1.Cols = 5
End Sub

Private Sub MSFlexGrid1_Click ()
   ' Put text in current cell.
   MSFlexGrid1.Text = "Here"
   ' Put text in third row, third column.
   MSFlexGrid1.Col = 2
   MSFlexGrid1.Row = 2
   MSFlexGrid1.Text = "There"
End Sub

The next example displays the location of the active cell and the range of the selection as a user selects a cell or range of cells. Notice that when selecting a range, the active cell doesn't 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 doesn't change.

To try this example, create a new project, add an MS Flex Grid control using the Components dialog box (from the Project menu, choose Components, and then check Microsoft Flex Grid Control), and then draw an MS Flex Grid and two labels. Copy the code into the Declarations section, and then press F5 to run the program.

Private Sub Form_Load ()
   MSFlexGrid1.Cols = 6   ' Set columns and rows.
   MSFlexGrid1.Rows = 7
End Sub

Private Sub MSFlexGrid1_RowColChange ()
   Msg = "Active Cell: " & Chr(64 + MSFlexGrid1.Col)
   Mst = Msg & MSFlexGrid1.Row
   Label1.Caption = Msg
End Sub

Private Sub MSFlexGrid1_SelChange ()
   Msg = "Selection: " & Chr(64 + MSFlexGrid1.SelStartCol)
   Msg = Msg & MSFlexGrid1.SelStartRow
   Msg = Msg & ":" & Chr(64 + MSFlexGrid1.SelEndCol)
   Msg = Msg & MSFlexGrid1.SelEndRow
   Label2.Caption = Msg
End Sub

Private Sub Form_Click ()
   ' This procedure moves the active cell around
   ' the perimeter of the selected range
   ' of cells with each click on the form.
   Dim GR, GC As Integer
   If MSFlexGrid1.Row = MSFlexGrid1.SelStartRow Then
      If MSFlexGrid1.Col = MSFlexGrid1.SelEndCol Then
         GR = 1: GC = 0
      Else
         GR = 0: GC = 1
      End If
   ElseIf MSFlexGrid1.Row = MSFlexGrid1.SelEndRow Then
      If MSFlexGrid1.Col = MSFlexGrid1.SelStartCol Then
         GR = -1: GC = 0
      Else
         GR = 0: GC = -1
      End If
   Else
      If MSFlexGrid1.Col = MSFlexGrid1.SelStartCol Then
         GR = -1: GC = 0
      Else
         GR = 1: GC = 0
      End If
   End If
   MSFlexGrid1.Row = MSFlexGrid1.Row + GR
   MSFlexGrid1.Col = MSFlexGrid1.Col + GC
End Sub