title: [VB.NET]Object reference not set to an instance of an object
body: <p>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)</p>
  
  <p><strong>CODE:</strong></p>
  
  <pre><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
  </code></pre>
  
  <blockquote>
    <p>ex.Message = <em>Object reference not set to an instance of an object</em> </p>
    
    <p>ex.InnerException = <em>empty</em></p>
    
    <p>ex.InnerException.Message = Makes program crash, goes to code screen,
    highlights <em>MsgBox(ex.InnerException)</em> line, and gives error: <em>Object
    reference not set to an instance of an object</em></p>
  </blockquote>
  
  <p><strong>ADDITIONAL INFO:</strong>
  Using QuickWatch on zdgv gives me all info. Using it on Rows after it(zdgv) says: <em>'Rows' is not declared. It may be inaccessible due to its protection level.</em> </p>
  
  <p>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. :/</p>
  
  <p>Thanks in advance.</p>
  
  <p><strong>EDIT1:</strong> 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".</p>
  
  <p><strong>EDIT2:</strong> This one was fail - newbie mistake.</p>
  
  <p><strong>EDIT3:</strong> using quickwatch on </p>
  
  <pre><code>zdgv.Rows(zdgv.SelectedRows(a).Index).Cells(0).Value.ToString 
  </code></pre>
  
  <p>it shows right value(correct one, without throwing errors) = "1".</p>