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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MSHFlexGrid Redraw Slow

Status
Not open for further replies.

RBSTR

Programmer
Joined
Nov 10, 2005
Messages
71
Location
GB
Hi

I have a form with 2 MSHFlexGrids whose contents are synchronised so same row data appears on both.

Further functionality allows the grid contents to be filtered where one cell value matches a value keyed by the user.

I perform the filter by looping through all the rows and if they do not match the value then set rowheight to 0.

My client has reported the screen refresh following a filter takes a long time.

In essence my code works as follows:

Code:
'Comment1
flxGrid2.Redraw = False
flxGrid1.Redraw = False
strFilter = "Value to Filter"

With flxGrid2

 For lngCnt = 1 To .Rows - 1
  If .TextMatrix(lngCnt, 2) = strFilter Then
   .RowHeight(lngCnt) = 0
  Else
   .RowHeight(lngCnt) = 1
  End If

  DoEvents
 Next 

 For lngCnt = 1 To .Rows - 1
  flxGrid1.RowHeight(lngCnt) = .RowHeight(lngCnt) 
  DoEvents
 Next 

End With

'Comment2
flxGrid2.Redraw = True
flxGrid1.Redraw = True
'Comment3

I have done some testing on a copy of the same data as my client's (4,840 rows of data)

The time to process between Comment1 and Comment2 is the same (1 second) on my local workstation as it is on my client's server.

The time to process between Comment2 and Comment3 (i.e. the issuing of the .redraw = true methods) is 2 seconds on my local workstation but 110 seconds on my client's server.

I am trying to understand why the redraw method may take so much longer on my client's server, plus how I could optimise it.

Does anyone have any suggestions?
 

Just wandering - how long does it take you to load all 4,840 rows of data in the first place? And do you load all of that from the ADO recordset?

If it is fast and it is a recordset, maybe filtering the recordset and re-populating the Grid would be the way to go?

Have fun.

---- Andy
 
Just a question...

If you have the redraw set to false what purpose do the Do Events server in the loops?
 
Many thanks for your responses.

Andy
maybe filtering the recordset and re-populating the Grid would be the way to go

Yes I do populate the grid from a recordset and population is quick.

My recordset (which comes from a select statement) also contains a blank field of data (i.e. select '') so the user can key values into the grid.

The user wants to be able to filter the grid but not lose data s/he had keyed into this column, so I developed the process I had (which works well on other grids in my app - albeit with less rows).

I could write this back to a recordset but would require a rework which I'm trying to avoid at present.

jadams0173
If you have the redraw set to false what purpose do the Do Events serve in the loops?
I may have a misunderstanding of what DoEvents does.
Regardless I have taken these out of my code. Now the process through to Comment3 takes one second on my client's server but it still then takes along time for the grid display to refresh.
This is where no code is being called and waiting for next user input and to me (and I may be wrong) suggests outside events are now 'catching up'?
If I put a DoEvents in immediately after Comment2 (before the redraw) I again find 110 seconds between Comment2 and Comment3 on my client's server.
 
Try it without any DoEvents. DoEvents yeilds the use of the processor back to the OS (my understanding). Are you using DoEvents to refresh your form?

If so try using the refresh method of the form.

 
Don't know if it will help but try making it different with something like;

'Comment1
flxGrid2.Redraw = False
flxGrid1.Redraw = False
strFilter = "Value to Filter"

Dim h as Long
With flxGrid2

For lngCnt = 1 To .Rows - 1

h = -1 * (.TextMatrix(lngCnt, 2) = strFilter)
.RowHeight(lngCnt) = h
flxGrid1.RowHeight(lngCnt) = h

Next

End With

'Comment2
flxGrid2.Redraw = True
flxGrid1.Redraw = True
'Comment3

 
Thanks for the responses

jadams0173
Are you using DoEvents to refresh your form
No I am using them to yield execution so that the operating system can process other events. I've removed them and the 110 seconds on my clients server to refresh the grid display now seems to be after the redraw properties are set, which is the last line of code in my process.

Hugh
I utilised your suggestion.
MSDN tells me redraw when false will not redraw after each change. So I wondered whether when I set redraw to true it does all the the changes in one go.
So I changed my process to only adjust the row height if needed (e.g. if rowheight was 0 and it is still to be filtered then no need to set rowheight=0 again) - thus reducing the number of changes/redraws required when redraw property is set to true.
Alas this does not appear to make a noticeable difference.

I am now concluding I may need to rework as per Andrzejek suggestion - writing the values keyed back to a recordset and then retrieving again from the recordset.
 
Try locking the grid while making the changes. You can use these API routines (fg is the grid, you can pass it in):
Code:
Sub LockGrid()

'   Keep grid from flickering - allows leaving grid displayed while filling - will
be blank

    Dim lRet As Long
    lRet = LockWindowUpdate(fg.hWnd)
    
End Sub

Sub ReleaseLock()

'   Release the lock on the grid

    Dim lRet As Long
    lRet = LockWindowUpdate(0)
    
End Sub

Don't know if you can lock both of them.



"I think we're all Bozos on this bus!" - Firesign Theatre [jester]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top