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?

[Webinar] Streamline your web hosting managementRegister Today

x
 
caraf_gConnect With a Mentor Commented:
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
 
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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
 
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
All Courses

From novice to tech pro — start learning today.