Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is it better to use MSHFlexGrid in bound or unbound mode

Status
Not open for further replies.

happyabc

IS-IT--Management
Joined
Mar 10, 2004
Messages
164
Location
IN
Is it better to use MSHFlexGrid in bound or unbound mode?
 
I don't really know if it one method is better than the other, just different.

One main advantage to leaving the grid unbound is that you have more control and flexibility over the data and how it is displayed, including formatting, calculations, editing and updating. The draw back is that it does require a bit more code.

Personally I have not bound my grids in years. I like to have the extra control.



zemp
 
What about the hierarchical display features? Will they still be available? And what about performance?
 
All features should still be available. It might be a little slower filling the grid - you'll want to use a forward-only cursor in your recordset and lock the grid or make in invisible while you fill it.

"I think we're all Bozos on this bus!" - Firesign Theatre [jester]
 
I don't know to lock the grid but I did make it invisible but its still giving an unseemly flash. Why should this be after all, in bound mode the grid has to be doing the same thing that is being done in code.
 
set the Redraw property to false when loading and formating the grid, and to true afterwards.
 
When populating a flexgrid and you wish to stop the flickering - have a look at MS KnowledgeBase item 198938.

"Life is full of learning, and then there is wisdom"
 
you can use the api which will lock the screen until you release it or when the grid is finished.It goes something like this...


Public Declare Function LockWindowUpdate Lib "user32" Alias "LockWindowUpdate" (ByVal hwndLock As Long) As Long


Than before starting the populating write:

LockWindowUpdate Me.hWnd


Than after populating

LockWindowUpdate 0


Hope this helps..at least it helped me.. i ahd the same problems


Nick
 
koala15: searching MSDN for "198938" produces no results.

Rest: what is the possibility that the Redraw property is the same as LockWindowUpdate?
 
Redraw is not the same as the API LockWindowUpdate! on the other hand if oyu're asking if it produces the same results....I don't know but i tried Redraw on my project and it didn't do the same thing as LockWindow update did!

Nick
 
Re: 198938

Here is the document text

PRB: MSFLexGrid Redraw May Not Function Correctly
ID: Q198938



--------------------------------------------------------------------------------
The information in this article applies to:

Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, version 6.0

--------------------------------------------------------------------------------


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.



MORE INFORMATION

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.


Add an MSFlexGrid to the default form.


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
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.



Additional query words:

Keywords : kbCtrl kbVBp600 kbGrpVBDB
Version : WINDOWS:6.0
Platform : WINDOWS
Issue type : kbprb



Last Reviewed: May 17, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.




--------------------------------------------------------------------------------
Send feedback to MSDN.Look here for MSDN Online resources.

"Life is full of learning, and then there is wisdom"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top