DATAGRID
Ola pessoal, estou com uma dúvida.
Fiz um form de pesquisa, com um datagrid e barra de progressão, segue abaixo as linhas de comando.
Imports System.Data.SqlClient
Public Class Pesquisa
Dim totalrows As Integer
Dim dt As New DataTable
Dim drr As SqlDataReader
Dim cmd As New SqlCommand
Dim adtp As New SqlDataAdapter
Dim linha As String = Application.StartupPath & [Ô]\SIAF.mdf[Ô]
Dim conn As New SqlConnection([Ô]Data source=.\SQLEXPRESS;AttachDbFilename=[Ô] & linha & [Ô];Integrated Security=True;User Instance=True[Ô])
Private Sub cmdcancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdcancel.Click
[ô]Fecha a tela
Me.Close()
End Sub
Private Sub dgpesquisa_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles DGPesquisa.MouseHover
[ô]Informação na barra de status
Principal.ToolStripStatusLabel1.Text = [Ô]Clique sobre a pesquisa para alterar ou editar[Ô]
End Sub
Private Sub Dgpesquisa_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles DGPesquisa.MouseLeave
[ô]Coloca o nome do utilizador na barra de status
Principal.ToolStripStatusLabel1.Text = [Ô]Utilizador: [Ô] & utilizador
End Sub
Private Sub Pesquisa_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If conn.State = ConnectionState.Closed Then conn.Open()
cmd.CommandText = [Ô]SELECT * FROM TBPais [Order Details][Ô]
cmd.Connection = conn
drr = cmd.ExecuteReader
Background.RunWorkerAsync()
DGPesquisa.DataSource = dt
txtregistos.Text = totalrows
barraprogressao.Value = 0
totalrows = 0
End Sub
Private Sub Background_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles Background.DoWork
With drr.Read
dt.Load(drr)
totalrows = dt.Rows.Count
End With
For Value As Integer = 0 To totalrows
Background.ReportProgress(Value, Nothing)
Threading.Thread.Sleep(0.1)
Next
End Sub
Private Sub Background_ProgressChanged(sender As Object, e As System.ComponentModel.ProgressChangedEventArgs) Handles Background.ProgressChanged
barraprogressao.Maximum = totalrows
barraprogressao.Value = e.ProgressPercentage
End Sub
End Class
Só que da dois erros:
1º Erro
This BackgroundWorker states that it doesn[ô]t report progress. Modify WorkerReportsProgress to state that it does report progress.
2º Erro
Não exibe nenhum registo.
Fiz um form de pesquisa, com um datagrid e barra de progressão, segue abaixo as linhas de comando.
Imports System.Data.SqlClient
Public Class Pesquisa
Dim totalrows As Integer
Dim dt As New DataTable
Dim drr As SqlDataReader
Dim cmd As New SqlCommand
Dim adtp As New SqlDataAdapter
Dim linha As String = Application.StartupPath & [Ô]\SIAF.mdf[Ô]
Dim conn As New SqlConnection([Ô]Data source=.\SQLEXPRESS;AttachDbFilename=[Ô] & linha & [Ô];Integrated Security=True;User Instance=True[Ô])
Private Sub cmdcancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdcancel.Click
[ô]Fecha a tela
Me.Close()
End Sub
Private Sub dgpesquisa_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles DGPesquisa.MouseHover
[ô]Informação na barra de status
Principal.ToolStripStatusLabel1.Text = [Ô]Clique sobre a pesquisa para alterar ou editar[Ô]
End Sub
Private Sub Dgpesquisa_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles DGPesquisa.MouseLeave
[ô]Coloca o nome do utilizador na barra de status
Principal.ToolStripStatusLabel1.Text = [Ô]Utilizador: [Ô] & utilizador
End Sub
Private Sub Pesquisa_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If conn.State = ConnectionState.Closed Then conn.Open()
cmd.CommandText = [Ô]SELECT * FROM TBPais [Order Details][Ô]
cmd.Connection = conn
drr = cmd.ExecuteReader
Background.RunWorkerAsync()
DGPesquisa.DataSource = dt
txtregistos.Text = totalrows
barraprogressao.Value = 0
totalrows = 0
End Sub
Private Sub Background_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles Background.DoWork
With drr.Read
dt.Load(drr)
totalrows = dt.Rows.Count
End With
For Value As Integer = 0 To totalrows
Background.ReportProgress(Value, Nothing)
Threading.Thread.Sleep(0.1)
Next
End Sub
Private Sub Background_ProgressChanged(sender As Object, e As System.ComponentModel.ProgressChangedEventArgs) Handles Background.ProgressChanged
barraprogressao.Maximum = totalrows
barraprogressao.Value = e.ProgressPercentage
End Sub
End Class
Só que da dois erros:
1º Erro
This BackgroundWorker states that it doesn[ô]t report progress. Modify WorkerReportsProgress to state that it does report progress.
2º Erro
Não exibe nenhum registo.
ok, o 2º erro já resolvi, pois faltava me a seguinte linha de comando
Private Sub Background_RunWorkerCompleted(sender As Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles Background.RunWorkerCompleted
DGPesquisa.DataSource = dt
txtregistos.Text = totalrows
barraprogressao.Value = 0
totalr
Só que agora tenho o erro 1 e outro erro.
Porque não me exibe o primeiro registo.
Private Sub Background_RunWorkerCompleted(sender As Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles Background.RunWorkerCompleted
DGPesquisa.DataSource = dt
txtregistos.Text = totalrows
barraprogressao.Value = 0
totalr
Só que agora tenho o erro 1 e outro erro.
Porque não me exibe o primeiro registo.
Bom pessoal, já consegui resolver o 1º erro.
Basta alterar nas propriedades do background.
workrReportsprogress para true
workrSupportscancellation para true
Só que ainda continua a ignorar o primeiro registo, visualiza sempre do segundo para frente
Basta alterar nas propriedades do background.
workrReportsprogress para true
workrSupportscancellation para true
Só que ainda continua a ignorar o primeiro registo, visualiza sempre do segundo para frente
Tópico encerrado , respostas não são mais permitidas