PRB: Grid Custom Control: LeftCol/TopRow Valid Values

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

- Professional Edition of Microsoft Visual Basic for Windows,

  versions 2.0 and 3.0
- Microsoft Professional Toolkit for Microsoft Visual Basic programming
  system for Windows, version 1.0

SYMPTOMS

The LeftCol and TopRow grid properties control the position of the scrollable region of a Grid custom control. When you attempt to set the LeftCol or TopRow grid properties to display the lower right region of a grid, you may receive the error "Invalid Column Value" (30010) or "Invalid Row Value" (30009), respectively.

WORKAROUND

The example given below in the More Information section shows how to determine the range of values that do not give errors.

STATUS

This behavior is by design.

MORE INFORMATION

A program can determine the maximum values allowed for LeftCol and TopRow by setting these properties to each valid column and row number, respectively, and then determining if the assignment caused an error. The example code below shows how to use this method.

The minimum values allowed for LeftCol and TopRow are always given by the values of the Grid custom control properties FixedCols and FixedRows, respectively.

Step-by-Step Example

  1. Start Visual Basic or from the File menu, choose New Project (ALT, F, N) if Visual Basic is already running. Form1 is created by default.

  2. From the File menu, choose Add File, and select the GRID.VBX custom control file. The Grid tool will appear in the Toolbox.

  3. Select the Grid tool from the Toolbox, and add a grid (Grid1) to Form1.

  4. Size the Grid and choose values for the Cols and Rows properties of the Grid.

  5. Place a command button (Command1) on Form1.

  6. Enter the following code in the Command1_Click event procedure:

       ' Example of how to call Grid_Scroll_Range to determine the
       ' range of values for Grid properties LeftCol and TopRow.
       Sub Command1_Click ()
          Dim msg As String          ' message string
          Dim max_LeftCol As Single  ' maximum LeftCol
          Dim max_TopRow As Single   ' maximum TopRow
    
          Call grid_scroll_range(grid1, max_LeftCol, max_TopRow)
    
          msg = "Valid Grid.LeftCol: "
          msg = msg + Format$(grid1.FixedCols) + ".."
          msg = msg + Format$(max_LeftCol) + Chr$(13) + Chr$(10)
          msg = msg + "Valid Grid.TopRow: "
          msg = msg + Format$(grid1.FixedRows) + ".."
          msg = msg + Format$(max_TopRow)
    
          MsgBox msg
       End Sub
    
    

  7. Enter the following code in the general Declarations section:

       ' grid_scroll_range
       '   Determines the maximum values allowable for grid LeftCol
       '   and TopRow. Minimum values are FixedCols and FixedRows.
       '   Parameters:
       '       grid    -- a Grid control
       '       LftMax  -- return value, maximum LeftCol value
       '       TopMax  -- return value, maximum TopRow value
       '
       Sub grid_scroll_range (grid As Control, LftMax!, TopMax!)
          Dim save As Integer     ' for restoring grid properties
    
          ' Calculate LftMax
          ' Try each column number to see if it causes a run-time
          ' error. Go in reverse order to minimize the number of
          ' tries to the number of columns displayed in the grid.
          save = grid.LeftCol
          On Error Resume Next
          For LftMax = grid.Cols - 1 To grid.FixedCols + 1 Step -1
             Err = 0
             grid.LeftCol = LftMax
             If Err = 0 Then
                Exit For
             End If
          Next
          grid.LeftCol = save
    
          ' Calculate TopMax
          ' Try each row number to see if it causes a run-time
          ' error. Go in reverse order to minimize the number of
          ' tries to the number of rows displayed in the grid.
          save = grid.TopRow
          On Error Resume Next
          For TopMax = grid.Rows - 1 To grid.FixedRows + 1 Step -1
             Err = 0
             grid.TopRow = TopMax
             If Err = 0 Then
                Exit For
             End If
          Next
          grid.TopRow = save
       End Sub
    


Additional reference words: 1.00 2.00 3.00
KBCategory: kbprg kbcode kbprb
KBSubcategory: PrgCtrlsCus


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.