Controls corrupted during Form_Load

I have a form that fills a listview control in the Form_Load.  The problem is that during the time that the listview is filling, the form displays itself as though it were only half loaded i.e. you can see through parts of it and the text of the command buttons etc is not displayed.  Due to the size of the database that is being used to fill the listview, the form can be in this messed up state for up to 20 seconds.  I was wondering if it is possible to ensure that a form displays its controls properly even thought the data in the listview is still loading.
LVL 1
justinhemphillAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Erick37Commented:
Private Sub Form_Load()
    Show
    'Continue loading
End Sub
0
Erick37Commented:
Make that:

Private Sub Form_Load()
    Dim i As Long
    Show
    Refresh '<-Important
    'Continue loading
End Sub
0
VbmasterCommented:
The Show method can't be used on modal forms, here's a solution for those..

Private Sub Form_Load()

  Static IsDone As Boolean
  If IsDone Then Exit Sub
  IsDone = True

  DoEvents
  'Load listview items

End Sub
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

caraf_gCommented:
NO NO NO NO. Don't display the form whilst your gathering the data. It looks naff.

Show a splash screen: load it, and show it modelessly. Doevents.

Now fill the form while it is NOT being displayed.
This can be done by putting code elsewhere, and not in the Form_Load procedure.

Example:

Load YourForm 'form is not yet shown
YourForm.APublicSubThatFillsTheListView
YourForm.Show '*now* it is shown

Added advantage: because the controls need no refreshing, the loading will be a lot quicker.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
justinhemphillAuthor Commented:
VBMaster, your solution seems to work (it is a modal form), however, nothing below the DoEvents gets executed.
0
justinhemphillAuthor Commented:
VBMaster, your solution seems to work (it is a modal form), however, nothing below the DoEvents gets executed.
0
VbmasterCommented:
Dang, the sub I thought of was the Form_Activate() NOT the Form_Load.

Private Sub Form_Activate()   <- this sub

  Static IsDone As Boolean
  If IsDone Then Exit Sub
  IsDone = True

  DoEvents
  'Load listview items

End Sub
0
amebaCommented:
>20 seconds
How many columns are in the listview? How many records are you loading?
0
SonalCommented:
may b u can use another form as the startup say form1 (something like a splach screen) In it you can call load event of the form2 where you have the data to be filled in the listview ( form2) then at the end call show of the form2 in form1 itself..hope that works..best of luck
0
caraf_gCommented:
Sonal, did you read all of this thread <g>
0
paul_tsekovCommented:
Hi VB fan,

  Your problem is that you try to fill some controls with data when they are visible.

   That makes a lot of problems.

Why don't you try it that way:
This is your Form module:
'-----------------------------
Option Explicit

Dim blnFirstTime as Boolean

Private Sub Form_Load()
  ListView1.Visible=False
  blnFirstTime=False
End Sub

Private Sub Form_Activate()
  If blnFirstTime=False
      Fill_ListView1
      blnFirstTime=True
      ListView1.Visible=True
  End If
End Sub

Private Sub Fill_ListView1()
 ' Place your code of filling
 ' the ListView1 here  
End Sub
'-------------------------------------
 This code you work good !!!

                 Pavel Tsekov
        email : paul_tsekov@yahoo.com

 
0
caraf_gCommented:
paul_tsekov, did YOU read all of this thread?
<getting slightly annoyed now>
0
justinhemphillAuthor Commented:
Where is the best place to put the DoEvents?
0
caraf_gCommented:
Wow. Thanks, Justin!
0
caraf_gCommented:
pavel,

My apologies for snapping at you - let's put it down to a bad day; no excuse, I know.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.