Solved

SLOW SHOWING WINDOWS FORM

Posted on 2012-12-28
15
179 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

920 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

16 Experts available now in Live!

Get 1:1 Help Now