VB Grid Custom Control: LeftCol/TopRow Valid Values

ID Number: Q80911

1.00

WINDOWS

buglist1.00

Summary:

The grid properties LeftCol and TopRow control the position of the

scrollable region of a Grid custom control. When you attempt to set

the grid properties LeftCol or TopRow to display the lower right

region of a grid, you may incorrectly receive the error "Invalid

Column Value" (30010) or "Invalid Row Value" (30009), respectively.

The example code below shows how to determine the range of values that

do not give these errors.

Microsoft has confirmed this to be a problem with the Grid custom

control supplied with Microsoft Professional Toolkit for Microsoft

Visual Basic programming system version 1.0 for Windows. We are

researching this problem and will post new information here as it

becomes available.

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.

Example

-------

1. Run 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 place a grid named Grid1

on Form1.

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

the Grid.

5. Place a command button named 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