Avatar of emi_sastra
emi_sastra
 asked on

SLOW SHOWING WINDOWS FORM

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.
Visual Basic.NET

Avatar of undefined
Last Comment
emi_sastra

8/22/2022 - Mon
Mike Tomlinson

"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...
emi_sastra

ASKER
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.
themrrobert

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
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Mike Tomlinson

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.
ASKER CERTIFIED SOLUTION
Éric Moreau

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
emi_sastra

ASKER
Hi Idle_Mind and  themrrobert,

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

Thank you.
SOLUTION
Mike Tomlinson

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
emi_sastra

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

Thank you.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Mike Tomlinson

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

ASKER
Yes, it improve showing form.

I would like also consider asynchronous data loading by emoreau.

Thank you.
emi_sastra

ASKER
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.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Éric Moreau

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.
emi_sastra

ASKER
-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 Moreau

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

Call this method from the form_load event
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
emi_sastra

ASKER
Hi All,

Thank you very much for your help.