I would like to know how to increase the speed of data loading into flexgrid from Database(SQL Server).currently im using a loop but this takes a lot of time when there are alot of data...pls give me a solution to this problem..

Thank you

Recommended Answers

All 3 Replies

Ancie, please show us the loop code you are using to load the grid. Your problem might lie there.

If the form is shown, you might be able to use LockWindowUpdate API in the following manner

LockWindowUpdate Grid.hWnd
'do loading here
LockWindowUpdate 0

Another method would be to hide the grid that you are loading and show a dummy grid along with a progress bar...

Good Luck

You might as well try to make the control invisible first, then when all the data has been loaded, set the control's visibility to true, for some controls, it increases the speed...

and just to add up if the loop makes your app hang...then try to insert a DoEvents keyword before the loop statement ending keyord...

For i = 0 to rs.RecordCount -1

'Your code here....to populate the flexgrid

DoEvents
Next i

or with the While loop statements, just add the DoEvents keyword before the Loop keyword

Do NOT While rs.EOF

'Your code here....to populate the flexgrid

DoEvents
Loop

NOTE: please take note of your usage of the DoEvents keyword, especially when you are performing long executing codes, it might perform undesireable effects...just like this one:

Private Sub Form_Load()
'While the loop executes, try to close the form, and notice that the loop still being executed even if the form has been unloaded...
Me.Show
For i = 0 To 10000
    Me.Caption = i
    DoEvents
Next i
End Sub

Anyway, the decision is all yours, of what technique you would use...Happy Coding!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.