Jump to content

Recommended Posts

Posted

Pessoal tenho este código:

idencomenda.Text = CStr(DataGridView1.CurrentRow.Cells(0).Value)

e da-me erro:A referência de objecto não foi definida como uma instância de um objecto.

isto porque neste momento nao tenho nados nessa celula, posso fazer algo para contornar isto?

Posted

e assim?


If IsDBNull(CStr(DataGridView1.CurrentRow.Cells(0).Value)) Or Len(CStr(DataGridView1.CurrentRow.Cells(0).Value)) = 0 then
       IdEncomenda.Text = string.empty
Else
       IdEncomenda.Text = CStr(DataGridView1.CurrentRow.Cells(0).Value)
End If

Posted

e assim?


If IsDBNull(CStr(DataGridView1.CurrentRow.Cells(0).Value)) Or Len(CStr(DataGridView1.CurrentRow.Cells(0).Value)) = 0 then
       IdEncomenda.Text = string.empty
Else
       IdEncomenda.Text = CStr(DataGridView1.CurrentRow.Cells(0).Value)
End If

da erro logo na condição:

A referência de objecto não foi definida como uma instância de um objecto.

Posted

Experimenta primeiro:

If DataGridView1.CurrentRow IsNot Nothing Then
    If DataGridView1.CurrentRow.Cells(0).Value IsNot Nothing Then

        IdEncomenda.Text = DataGridView1.CurrentRow.Cells(0).Value.ToString

    End If
End If

Desta forma verifica primeiro se existe alguma linha seleccionada, depois se houver vai verificar se a linha tem dados, e se tiver dados, ai sim vai colocar os dados na textbox.

Posted

Experimenta primeiro:

If DataGridView1.CurrentRow IsNot Nothing Then
    If DataGridView1.CurrentRow.Cells(0).Value IsNot Nothing Then

        IdEncomenda.Text = DataGridView1.CurrentRow.Cells(0).Value.ToString

    End If
End If

Desta forma verifica primeiro se existe alguma linha seleccionada, depois se houver vai verificar se a linha tem dados, e se tiver dados, ai sim vai colocar os dados na textbox.

para que resolveu 🙂 obrigado

  • 2 months later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.