Solved

SLOW SHOWING WINDOWS FORM

Posted on 2012-12-28
15
177 Views
Last Modified: 2013-01-04
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.
0
Comment
Question by:emi_sastra
  • 7
  • 4
  • 3
  • +1
15 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 38728745
"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...
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38728754
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.
0
 
LVL 13

Expert Comment

by:themrrobert
ID: 38728763
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
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 38728765
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.
0
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 400 total points
ID: 38729252
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38730584
Hi Idle_Mind and  themrrobert,

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

Thank you.
0
 
LVL 85

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 100 total points
ID: 38731140
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

0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 1

Author Comment

by:emi_sastra
ID: 38731579
-You could also try forcing a repaint before the other loading code continues:
At what event ?

Thank you.
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 38731647
The Load() event...or wherever your code that loads the controls is.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38731773
Yes, it improve showing form.

I would like also consider asynchronous data loading by emoreau.

Thank you.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38731775
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.
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 38732468
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.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 38733855
-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.
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 38734420
create a LoadData method. this method will contain the BeginExecuteXXX and everything to get the results.

Call this method from the form_load event
0
 
LVL 1

Author Closing Comment

by:emi_sastra
ID: 38745933
Hi All,

Thank you very much for your help.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now