Joca Posted October 24, 2009 at 07:31 PM Report Share #293210 Posted October 24, 2009 at 07:31 PM Boa noite, Eu consigo percorrer as linhas de uma DataGridView, desde o início, fazendo algo tal como o seguinte. Em que: - "btnSeguinte" é um botão; - "dgvExibeDados" é a DataGridView; - e, o "ds" é a dataset obtida via OleDb. Private Sub btnSeguinte_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSeguinte.Click Dim _indiceColuna As Integer = dgvExibeDados.CurrentCell.ColumnIndex Dim _indiceLinha As Integer = dgvExibeDados.CurrentCell.RowIndex Dim _TotalLinhas As Integer ' Dim _i As Integer = -1 <- declarado no inicio _TotalLinhas = ds.Tables("TESTE").Rows.Count _i = _i + 1 txtDados1.Text = ds.Tables("TESTE").Rows(_indiceLinha + _i).Item(_indiceColuna) end sub A minha questão é: como é que faço para reiniciar a contagem da variável "_i" se eu seleccionar uma outra linha na datagridview? Pensei em usar também a seguinte opção, mas não estou a ter muito sucesso.... 😛 Alguma ideia? Dim dr As DataGridViewRow = dgvExibeDados.CurrentRow txtDados1.Text = dgvExibeDados.Rows.GetNextRow(dr.Index, DataGridViewElementStates.Visible) Link to comment Share on other sites More sharing options...
Gooden Posted October 27, 2009 at 09:51 AM Report Share #293518 Posted October 27, 2009 at 09:51 AM =) eu gosto de ajudar pessoas 👍 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim i As Integer = DataGridView1.CurrentCell.RowIndex DataGridView1.Rows(i).Selected = False DataGridView1.CurrentCell = DataGridView1.Rows(i + 1).Cells(0) DataGridView1.Rows(i + 1).Selected = True Label1.Text = DataGridView1.Rows(DataGridView1.CurrentCell.RowIndex).Cells(0).Value End Sub No Form Load apos o carregamento da grid meti isto: Label1.Text = DataGridView1.Rows(DataGridView1.CurrentCell.RowIndex).Cells(0).Value também meti o select mode como fullrow mas isso não interessa muito =) Link to comment Share on other sites More sharing options...
Joca Posted October 27, 2009 at 11:24 PM Author Report Share #293640 Posted October 27, 2009 at 11:24 PM Graças à tua ajuda, percebi onde estava a minha asneira. Readaptei o teu código para ficar assim no evento click do botão: Dim _indiceColuna As Integer = dgvExibeDados.CurrentCell.ColumnIndex Dim _indiceLinha As Integer = dgvExibeDados.CurrentCell.RowIndex Dim _TotalLinhas As Integer Dim _i As Integer = dgvExibeDados.CurrentCell.RowIndex _TotalLinhas = dgvExibeDados.Rows.Count dgvExibeDados.CurrentCell = dgvExibeDados.Rows(_i + 1).Cells(_indiceColuna) txtDados1.Text = dgvExibeDados.Rows(dgvExibeDados.CurrentCell.RowIndex).Cells(_indiceColuna).Value E, alterei o código do evento click da dgvExibeDados (a DatagridView) para actualizar de imediato a Textbox: Dim _indiceColuna As Integer = dgvExibeDados.CurrentCell.ColumnIndex Dim _indiceLinha As Integer = dgvExibeDados.CurrentCell.RowIndex Dim _TotalLinhas As Integer Dim _i As Integer = dgvExibeDados.CurrentCell.RowIndex _TotalLinhas = dgvExibeDados.Rows.Count txtDados1.Text = dgvExibeDados.Rows(_i).Cells(_indiceColuna).Value Obviamente, que tem código repetido e, talvez a ser alterado (tal como o uso do selected que indicaste... ainda em estudo) mas, para testes vai servir para já. Agora já posso trabalhar descansado na "captura" dos erros usando a variável "_Total de linhas" entre outras futuras variáveis. Obrigado pela dica! 👍 Link to comment Share on other sites More sharing options...
Joca Posted October 27, 2009 at 11:27 PM Author Report Share #293641 Posted October 27, 2009 at 11:27 PM off topic: Onde está a opção do "Topic Solved"? Costumava ser em baixo. Link to comment Share on other sites More sharing options...
Gooden Posted October 28, 2009 at 09:03 AM Report Share #293662 Posted October 28, 2009 at 09:03 AM Devido ao layout do forum ainda não está disponível. Altera o novo do tópico [Resolvido] assim quando estiver activa poder-se a marcar como tal. Link to comment Share on other sites More sharing options...
Joca Posted October 28, 2009 at 08:48 PM Author Report Share #293772 Posted October 28, 2009 at 08:48 PM Feito! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now