Hide a form while the Listbox is loaded from a datable

  • Thread starter Thread starter PAPutzback
  • Start date Start date
P

PAPutzback

I have a form that when it loads it fires off a second thread to load a
datatable. This datatable contains a list of names and ids that the user
may want to add to their criteria. So I have a button that once the
thread completes it beccomes enabled and the datable gets bound to a
listbox that shows up on the new form. But there is a delay, which I am
guessing is when the listbox is preparing to paint itself with the bound
data.

Is there a way to have the form preload when the thread finishes so when
the user runs the form.show code that the form pops up instantly.

Thanks,
Phil Putzback
 
It seems to me that you should load the data before showing the form to the
user. It sounds like you need a splash screen.

Load the splash screen in a new thread, then launch and load the form in the
main thread while the splash screen is displayed. When the form is finished
loading then close the splash screen and show then main screen. Since
everything for the main screen is already loaded, it will show instantly.
That's how I've handled it. There is no need to have your main form launch
a seperate thread to load the data in this way of doing it.

Chris
 
The mainform is where they enter criteria, date range for example. Now
while they are entering this data I have loaded the datatable which
will be bound to the list box on the popup screen if the user doesn't
know a specific id and has to look up by name. There are about 12,000
records but the datatable takes only about 10 seconds to load. But
showing the form with the listobx takes an equal amount of time to
show. The main criteria screen is basically my splash screen. By the
time they get to the field where they would look at the form the table
is loaded. My delay is in the showing of the form not the data being
pulled from the server.

So maybe another thread then?

Thanks,
Phil
 
My Code
Dim My_PCPForm As New frm_PCPlist
Private PCPdt As New DataTable
Private m_PCPThread As Thread


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
My_PCPForm.Show()
End Sub

Private Sub frm_Provider_Eligibility_Load(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'/// <summary>
'/// To speed up the process of displaying the list of
providers.
'/// create a seperate thread to create the datatable in the
background
'/// </summary>
Dim ts1 As ThreadStart = New ThreadStart(AddressOf preLoadPCP)
m_PCPThread = New Thread(ts1)
m_PCPThread.IsBackground = True
m_PCPThread.Start()
End Sub

Private Sub preLoadPCP()
Dim PCPSql As String = _
"Select rtrim(provider) + ' | ' + rtrim(plast_nme)
+', ' + " _
& "rtrim(pfirst_nme) as name, provider from provider
order by plast_nme,pfirst_nme"
Dim PCPCmd As New SqlCommand(PCPSql, conn_EMC)
Dim PCPAdptr As New SqlDataAdapter(PCPCmd)
PCPAdptr.Fill(PCPdt)
My_PCPForm.PCPList.DataSource = PCPdt
My_PCPForm.PCPList.DisplayMember = "name"
My_PCPForm.PCPList.ValueMember = "provider"
My_PCPForm.Hide()
Button1.Enabled = True
The delay is the button click event. Is that because of the listbox.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top