Here are some insights as to how to speed up filling in a grid control. I timed the amortization chart program I made and found the following;
1. Using the controls "additem" method is horribly slow. I believe this was designed to allow you to insert rows into the table where needed, the method takes care of shifting the rest of the rows down etc.
Example
(bad
);
for iCount = 1 to 360
gridControl.AddItem
("Cat" & vbTab & "in" & vbTab & "the" & vbTab & "Hat"
next iCount
Using this method in my amortization chart program took forever, just shy of 2 minutes!! 117 seconds to be precise. The better way to go is to pre-allocate your chart and fill as follows;
Example
(better
);
grdControl.Rows = 360
for iCount = 1 to 360
grdControl.TextMatrix(0, 0) = "Cat"
grdControl.TextMatrix(0, 1) = "in"
grdControl.TextMatrix(0, 2) = "the"
grdControl.TextMatrix(0, 3) = "Hat"
next iCount
This was like lightning compared to other method, total time was 12 seconds.
2. Set the control to visible=false while updating and then back to true when complete.
Example
(best
);
grdControl.Visible = False
for iCount = 1 to 360
grdControl.TextMatrix(0, 0) = "Cat"
grdControl.TextMatrix(0, 1) = "in"
grdControl.TextMatrix(0, 2) = "the"
grdControl.TextMatrix(0, 3) = "Hat"
next iCount
grdControl.Visible = True
Final result, the grid is filled in 5 seconds!! Of course for the "bestest" time - code it in C
(or assembly
)
Also, my code had proper indenting, however I can't figure out how to get that to "stick" in the posting. Hopefully still readable enough! If someone can tell me how to do that, I'll come back and edit this post to make it look purdy!
Hope that helps someone coding in VB. Also I attached the amortization chart for anyone interested - the 2 minute slow one - you can get the fast one when you register the software at my site for the hpc:factor special of $40, mwwwaahhhahhahaaa - er no, actually the fast one is attached! Ohh, almost forgot - no error checking and the starting date does nothing at this point so use at your own risk - AND if your HPC blows up - don't call me!!
Edited by Cyberstorm 2006-02-22 11:04 PM