Hi Adriano,
It's not too difficult.
Start by adding a timer and a progress bar to the form, and add a public
variable to the form class as
Public alarmcounter As Integer = 1
Then set the timer in the load event:
timer1.start
Add a timer_tick method with this code:
alarmcounter += 1
If alarmcounter > 2 Then
Timer1.Stop()
loader.PerformClick()
End If
'loader' is a button control that simply says 'Loading....' and is set not
to be able to be clicked. However, it does have a click event, thus the
performclick above. Then this in the click event:
loader.Enabled = False
me.parent.cursor = Cursors.WaitCursor
Application.DoEvents()
If gl_sqlexpression = "6 <> 7" Then
Me.SqlSelectCommand1.CommandText = "SELECT rinvnum, invnum, qty, title,
brname, bipad, issuecode, imcacct, uprice, cprice, shi" & _
"p_dt, billed, onsaledt, bipterms, ptype, rectype, isquart, raf, ponumber,
vflag, mcycle," & _
" rowid FROM invdet"
Else
Me.SqlSelectCommand1.CommandText = "SELECT rinvnum, invnum, qty, title,
brname, bipad, issuecode, imcacct, uprice, cprice, shi" & _
"p_dt, billed, onsaledt, bipterms, ptype, rectype, isquart, raf, ponumber,
vflag, mcycle," & _
" rowid FROM invdet WHERE " & gl_sqlexpression
'" rowid FROM invdet WHERE bipad in ('18770', '18778', '01503')"
End If
SqlDataAdapter1.SelectCommand.CommandTimeout = 1200
Me.SqlDataAdapter1.SelectCommand = Me.SqlSelectCommand1
If Mid(gl_sqlexpressioncount, 1, 1) <> "z" Then
gl_sqlexpressioncount = gl_sqlexpression
End If
Dim oconn As New SqlConnection(globalconnectionstring)
oconn.ConnectionString = globalconnectionstring
oconn.Open()
Dim cmd As SqlCommand = oconn.CreateCommand()
cmd.CommandText = "select count(*) from invdet WHERE (ship_dt >= " & Chr(39)
& gl_browsestartdate & Chr(39) & ")"
cmd.CommandText = "select count(*) from invdet where " &
gl_sqlexpressioncount
cmd.CommandTimeout = 1200
Dim rows As Integer
If Mid(gl_sqlexpressioncount, 1, 1) = "z" Then
rows = CInt(Mid(gl_sqlexpressioncount, 2))
Else
Try
rows = CInt(cmd.ExecuteScalar)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End If
oconn.Close()
Dim dt As DataTable
dt = Invdetds2.Tables(0)
AddHandler dt.RowChanged, New DataRowChangeEventHandler(AddressOf
DataTableRow_Changed)
pbar.Maximum = rows
pbar.Step = pbar.Maximum / 30
pbar.Visible = True
pbar.Minimum = 1
' Set the initial value of the ProgressBar.
pbar.Value = 1
pbar.PerformStep()
Try
Me.SqlDataAdapter1.Fill(Me.Invdetds2)
Catch ex As Exception
MessageBox.Show("Invalid SQL Expression", "SQL Error", MessageBoxButtons.OK,
MessageBoxIcon.Hand)
Me.Close()
Exit Sub
End Try
The key is an event called datatablerow_changed, which is added via
addhandler in the code above; here's the code for the datatablerow_changed
event:
Public Sub DataTableRow_Changed(ByVal Sender As Object, ByVal e As
System.Data.DataRowChangeEventArgs)
' The DataRow has changed. update pbar
glf_icount += 1
If glf_icount > (pbar.Maximum / 15) Then
glf_icount = 0
pbar.PerformStep()
Application.DoEvents()
End If
Once the table loads, simply make the button and the progress bar invisible.
HTH,
Bernie Yaeger