'Undefined object reference for an instance of an object. ' Datagridview.Currentrow

Asked

Viewed 56 times

0

System.Windows.Forms.DataGridView.Currentrow.get returned Nothing.

    Me.StatusTableAdapter.Fill(Me.DataSet1.Status)
    Me.FornecedorTableAdapter.Fill(Me.DataSet11.Fornecedor)
    Me.ProdutosTableAdapter.Fill(Me.DataSet1.Produtos)

 >  Dim cod = Form1.DataGridView1.CurrentRow.Cells(0).Value
    cod_txt.Text = cod

Even having a line selected in datagridview1 in Form1 it returns Nothing

I tried to load the data into the table with the following code:

Form1.ProdutosTableAdapter.Fill(Form1.DataSet1.Produtos)

And somehow it worked, but System.Windows.Forms.DataGridView.Currentrow.get only resumed the first line and not the one that was selected

In Form1 I call this other form with a button, follows code:

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    Dim alteraçao As Alteração
    alteraçao = New Alteração
    alteraçao.ShowDialog()
End Sub

I thought about using a configuration variable, but I think there’s another way around this error. I tried to select specifically a line and not Currentrow and resumed the right value of the line, but does not meet the purpose of the form, example:

Dim cod = Form1.DataGridView1.Rows(1).Cells(0).Value
cod_txt.Text = cod

I wanted exactly the line that is selected in datagridview1 but it resumes this error when I call "Form1.Datagridview1.CurrentRow.Cells(0). Value" in another form.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.