I am trying to add a column value from a selected row in my datagridview to Collection (but I get the same error if I do this with a 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 object instance
ex.InnerException = empty
ex.InnerException.Message = Makes a program error, goes to the code screen, selects the line MsgBox (ex.InnerException) and gives an error: Object link is not set to the object instance
FURTHER INFORMATION: Using QuickWatch on zdgv gives me all the info. Using it on the lines after it (zdgv) says: "Lines" are not declared. It may not be available due to its level of protection.
PS Yes, I googled, but not a single problem was alike. Yes, I searched here, but no information. I also tried r / visualbasic - nothing ... I even tried searching for C # related with this error - nothing.: /
Thanks in advance.
EDIT1: I tried to make a datagridview without data binding in a new project and add one value from it to the collection - same error. I think I should google about "Setting up an object reference to an object instance".
EDIT2: This error was a bug - newbie.
EDIT3: using quick view
zdgv.Rows(zdgv.SelectedRows(a).Index).Cells(0).Value.ToString
it shows the correct value (fix one, without throwing errors) = "1".
source share