Microsoft KB Archive/80911

= PRB: Grid Custom Control: LeftCol/TopRow Valid Values =

Article ID: 80911

Article Last Modified on 11/18/2003

-

APPLIES TO


 * Microsoft Visual Basic 2.0 Professional Edition
 * Microsoft Visual Basic 3.0 Professional Edition
 * Microsoft Professional Toolkit for Microsoft Visual Basic programming system for Windows

-



This article was previously published under Q80911



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 &quot;Invalid Column Value&quot; (30010) or &quot;Invalid Row Value&quot; (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
 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. From the File menu, choose Add File, and select the GRID.VBX custom control file. The Grid tool will appear in the Toolbox. Select the Grid tool from the Toolbox, and add a grid (Grid1) to Form1. Size the Grid and choose values for the Cols and Rows properties of the Grid. Place a command button (Command1) on Form1.  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 = &quot;Valid Grid.LeftCol: &quot; msg = msg + Format$(grid1.FixedCols) + &quot;..&quot; msg = msg + Format$(max_LeftCol) + Chr$(13) + Chr$(10) msg = msg + &quot;Valid Grid.TopRow: &quot; msg = msg + Format$(grid1.FixedRows) + &quot;..&quot; msg = msg + Format$(max_TopRow)

MsgBox msg End Sub </li>  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 </li></ol>

Additional query words: 1.00 2.00 3.00

Keywords: kbprb KB80911

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.