Microsoft KB Archive/198938

= PRB: MSFLexGrid Redraw May Not Function Correctly =

Article ID: 198938

Article Last Modified on 5/8/2003

-

APPLIES TO


 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q198938



SYMPTOMS
After setting the TopRow property of the MSFlexGrid, setting the Redraw property to True does not cause the MSFlexGrid to be automatically redrawn.



CAUSE
Microsoft is researching this problem and will post new information in the Microsoft Knowledge Base as it becomes available.



RESOLUTION
There are a couple of workarounds to this problem. You can use the code in these workarounds in place of the code shown in the MORE INFORMATION section of this article   If you replace the MSFlexGrid1_Click event in the MORE INFORMATION section with the following code, it works as expected: Private Sub MSFlexGrid1_Click

With MSFlexGrid1

.Redraw = True If .Row = .Rows - 1 Then .TopRow = 2 Debug.Print "Right After Setting .Top Row: " & .TopRow

End If

End With

Debug.Print "After leaving With block: " & MSFlexGrid1.TopRow

End Sub -or-

  Using the above workaround will get the MSFlexgrid to move to the correct position. However, doing so may cause the grid to flicker when filling. To avoid this flickering you can use the LockWindowUpdate API call as noted in the below code. Instead of using the above code, replace the code in the MSFlexGrid_Click event with the following: Private Declare Function LockWindowUpdate Lib "user32" _ (ByVal hwndLock As Long) As Long

Private Sub fgrItemGrid_Click

lres = LockWindowUpdate(Me.hWnd) 'Lock repaints

With fgrItemGrid

.Redraw = True If .Row = .Rows - 1 Then .TopRow = 2 Debug.Print "Right After Setting .Top Row: " & .TopRow

End If

End With

lres = LockWindowUpdate(0&) 'Release Lock

Debug.Print "After leaving With block: " & fgrItemGrid.TopRow

End Sub NOTE: The LockWindowUpdate API can be used to enable or disable a window from repainting. In workaround 2 above, it is used to prevent the window from repainting. 



STATUS
Microsoft is researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.



Steps to Reproduce Behavior
 Start a new Visual Basic 6.0 standard EXE. From the Project menu, choose Components and add a reference to the Microsoft FlexGrid Control 6.0.</li> Add an MSFlexGrid to the default form.</li>  Cut and paste the following code into the form: Private Sub MSFlexGrid1_Click

With MSFlexGrid1

.Redraw = False If .Row = .Rows - 1 Then .TopRow = 2 Debug.Print "Right After Setting .Top Row: " & .TopRow

End If      .Redraw = True '.Refresh

End With

Debug.Print "After leaving With block: " & MSFlexGrid1.TopRow

End Sub

Private Sub Form_Load With MSFlexGrid1 .RowHeightMin = 288 .Cols = 10 .Rows = 5 .TextMatrix(0, 1) = "Row 0" .TextMatrix(1, 1) = "Row 1" .TextMatrix(2, 1) = "Row 2" .TextMatrix(3, 1) = "Row 3" .TextMatrix(4, 1) = "Row 4" .Width = 4095 .Height = 1600 End With End Sub </li> Click on the "Row 4" cell. The code in the Click event will execute. However, the grid will not refresh and move up so that the TopRow is now 2.

NOTE: Forcing a refresh with the .Refresh method does not correct this problem.</li></ol>

Keywords: kbprb kbctrl KB198938

-

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

© Microsoft Corporation. All rights reserved.