SLOW SHOWING WINDOWS FORM

emi_sastra
emi_sastra used Ask the Experts™
on
Hi All,

I have experienced of slow showing windows form, because I have to load huge data to datagridview or other tasks.

I want to show the form first then after that loading data to gridview.

How could I solve this problem ?

Thank you.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009

Commented:
"I want to show the form first then after that loading data to gridview."

Wire up the Shown() event of the Form, and place your code to load the grid in there.  You could also use the BackgroundWorker() control to do the query in the background...

Author

Commented:
Hi Idle_Mind,

-Wire up the Shown() event of the Form
I don't get this ?

-You could also use the BackgroundWorker() control to do the query in the background...
Any sample of it ?

Thank you.
Double click on the form and select the Shown() event. Put your code in there.  

(my code is just a sample you need to get the event from the IDE.
Public Sub Shown()
'Load Database code

End Sub


Here is how to use background worker: http://msdn.microsoft.com/en-us/library/cc221403%28v=vs.95%29.aspx
Expert Spotlight: Joe Anderson (DatabaseMX)

We’ve posted a new Expert Spotlight!  Joe Anderson (DatabaseMX) has been on Experts Exchange since 2006. Learn more about this database architect, guitar aficionado, and Microsoft MVP.

Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009

Commented:
Select the Form.  In the Properties Pane, bottom right by default, click on the "Lightning Bolt" icon.  Scroll down and find the "Shown" entry and double click to the right of it.
Senior .Net Consultant
Top Expert 2016
Commented:

Author

Commented:
Hi Idle_Mind and  themrrobert,

There is no big difference with between shown and load event.

Thank you.
Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009
Commented:
You could also try forcing a repaint before the other loading code continues:
Me.Show()
Application.DoEvents()
' ... rest of the loading code ...

Open in new window

Author

Commented:
-You could also try forcing a repaint before the other loading code continues:
At what event ?

Thank you.
Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009

Commented:
The Load() event...or wherever your code that loads the controls is.

Author

Commented:
Yes, it improve showing form.

I would like also consider asynchronous data loading by emoreau.

Thank you.

Author

Commented:
Hi emoreau,

Where to put the asynchronous data loading, at what event in order to make the data appear after form has shown?

Thank you.
Éric MoreauSenior .Net Consultant
Top Expert 2016

Commented:
you can call the BeginExecuteXXX directly from the form_load event but I would create a LoadData method (called by the form_load event for that purpose.

Author

Commented:
-you can call the BeginExecuteXXX directly from the form_load event but I would create a LoadData method (called by the form_load event for that purpose.
- I am sorry, miss your point. BeginExecuteXXX  at load event but LoadData at load event also ?

Thank you.
Éric MoreauSenior .Net Consultant
Top Expert 2016

Commented:
create a LoadData method. this method will contain the BeginExecuteXXX and everything to get the results.

Call this method from the form_load event

Author

Commented:
Hi All,

Thank you very much for your help.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial