title: C# reading datagridview from one form to another form
body: <p>I have two forms, one contains a datagridview control with a data source from MS Access. Data is properly displayed on the datagridview. First I select a cell in that data grid view, then I obtain the Row Index of the currently selected cell. I use that Row Index in an accessor function (code is in the main form):</p>
  
  <pre><code>public String Name
  { 
      get 
      { 
          return dataGridView1.Rows[selrow].Cells[1].Value.ToString(); 
      } 
  }
  </code></pre>
  
  <p>selrow contains the row index of the currently selected cell. Next, I click a button "Edit record" and this it displays my 2nd form as a modal form. I want to display the value of the above accessor in a text box, so code goes like this (code is in the 2nd form):</p>
  
  <pre><code>private void EditRecord_Load(object sender, EventArgs e)
  {
      CashLoan main = new CashLoan();
      txtEName.Text = main.name;
  }
  </code></pre>
  
  <p>But when I try to run and debug, I get this "Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index" directed at my accessor function. I can't seem to find the source of the problem. Thank you in advance. </p>