Friday, 16 August 2013

[VB.NET]Object reference not set to an instance of an object

[VB.NET]Object reference not set to an instance of an object

INFO: I'm trying to add value of column from selected row on my
datagridview to Collection(but I get same error if I do it with List or
Array)
CODE:
Dim zdgv = MyDataGridView
For a = 0 To zdgv.SelectedRows.Count - 1
MsgBox(zdgv.Rows(zdgv.SelectedRows(a).Index).Cells(0).Value.ToString)
Try
MyCollection.Add(zdgv.Rows(zdgv.SelectedRows(a).Index).Cells(0).Value.ToString)
Catch ex As Exception
MsgBox(ex.Message)
MsgBox(ex.InnerException)
End Try
Next
ex.Message = Object reference not set to an instance of an object
ex.InnerException = empty
ex.InnerException.Message = Makes program crash, goes to code screen,
highlights MsgBox(ex.InnerException) line, and gives error: Object
reference not set to an instance of an object
ADDITIONAL INFO: Using QuickWatch on zdgv gives me all info. Using it on
Rows after it(zdgv) says: 'Rows' is not declared. It may be inaccessible
due to its protection level.
P.S. Yes I've googled, but none problem was similar. Yes I've searched
here but no info. I've tryed r/visualbasic too - nothing... I've even
tryed search for c# related stuff with this error - nothing. :/
Thanks in advance.
EDIT1: I've tryed make non-databound datagridview in new project, and add
one value from it to collection - same error. I guess I should go google
about "Setting Reference of Object to an Instance of an Object".

No comments:

Post a Comment