vasco16 Posted May 31, 2009 at 02:24 PM Report #268750 Posted May 31, 2009 at 02:24 PM 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?
PNDmartins Posted May 31, 2009 at 07:55 PM Report #268787 Posted May 31, 2009 at 07:55 PM fazes assim: If DataGridView1.CurrentRow.Cells(0).Value IsNot Nothing Then IdEncomenda.Text = DataGridView1.CurrentRow.Cells(0).Value.ToString End If
axpppp Posted June 1, 2009 at 02:35 PM Report #268969 Posted June 1, 2009 at 02:35 PM exprimenta CStr(DataGridView1.CurrentRow.Cells(0).Value) = idencomenta.text
vasco16 Posted June 1, 2009 at 08:50 PM Author Report #269084 Posted June 1, 2009 at 08:50 PM ambas soluções apresentadas dao o erro: A referência de objecto não foi definida como uma instância de um objecto.
vasco16 Posted June 2, 2009 at 08:29 PM Author Report #269412 Posted June 2, 2009 at 08:29 PM ninguem tem ideia de como isto se resolve?S:
Guest PauloR Posted June 2, 2009 at 10:06 PM Report #269462 Posted June 2, 2009 at 10:06 PM 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
vasco16 Posted June 3, 2009 at 06:46 AM Author Report #269492 Posted June 3, 2009 at 06:46 AM 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.
Soulsick Posted June 3, 2009 at 11:00 PM Report #269780 Posted June 3, 2009 at 11:00 PM Hum, podes postar mais código? Isso normalmente acontece-me, quando me esqueço de colocar um New...
PNDmartins Posted June 4, 2009 at 12:01 PM Report #269850 Posted June 4, 2009 at 12:01 PM 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.
vasco16 Posted June 4, 2009 at 08:58 PM Author Report #270009 Posted June 4, 2009 at 08:58 PM 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
Ruben program Posted August 17, 2009 at 11:14 AM Report #283578 Posted August 17, 2009 at 11:14 AM pessoal kero digitar a idade de uma pessoa num textbox e filtrar o datagrid e mostrar logo a pessoa com akela idade estou desenvolvendo em C# windows aplicacion. help??
Ruben program Posted August 17, 2009 at 11:19 AM Report #283580 Posted August 17, 2009 at 11:19 AM ninguem tem ideia de como isto se resolve?S: possivelmente poderá faltar uma namespace/reference ao teu projecto. 🙂
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