title: How to pass the whole column of values inside dataGridView into method?
body: <p>I have a dataGridView containing longitude and latitude value.</p>
  
  <p>I need to make use with the value by passing it into a <code>DoSomethingMethod()</code>.</p>
  
  <p>I am not familiar with dataGridView and therefore I copy all the value from dataGridView and handle it wit <code>List&lt;&gt;</code></p>
  
  <p>Below is my code to manipulate the data inside dataGridView</p>
  
  <pre><code>Public Main()
  {
      List&lt;double&gt; lst_Long = new List&lt;double&gt;();
      List&lt;double&gt; lst_Latt = new List&lt;double&gt;();
  
      for (int rows = 0; rows &lt; dataGridView1.Rows.Count; rows++)
      {
          lst_Long.Add(Convert.ToDouble(dataGridView1.Rows[rows].Cells["Long"].Value));
          lst_Latt.Add(Convert.ToDouble(dataGridView1.Rows[rows].Cells["Latt"].Value));            
      }
  
      int ColumnCount = lst_Long.Count - 1;
      int RowCount = lst_Row.Count - 1;
  
      //Pass the list to DoSomethingMethod
      DoSomethingMethod(lst_Long , lst_Latt, ColumnCount, RowCount);
  }
  
  DoSomethingMethod(List&lt;double&gt; lst_long, List&lt;double&gt; lst_latt, int ColumnCount, int RowCount)
  {
      for (int iColumn = 0; iColumn &lt; ColumnCount; iColumn++)
      {
          for (int iRow = 0; iRow &lt; RowCount; iRow++)
          {
               // access my latitude value and longitude value here
               double myX = lst_latt[iRow]
               double myY = lst_long[iRow]
  
              // do some processing here with the value, lets say....
              double myNewX = myX + 10;
              double myNewY = myY + 10;
  
              PassNewDataToAnotherMethod( myNewX , myNewY );
          }
  
      }
  }
  </code></pre>
  
  <p>I would like to ask, if there is any other way to direct use and get the cell value from the dataGridView at <code>Columns["Long"]</code> and <code>Columns["Latt"]</code> and do the similar thing with out copy value from dataGridView into the list?</p>
  
  <p>Thanks~</p>
  
  <p><strong>Update</strong>: Below is my DGV table (The data is random, not real)</p>
  
  <p><img src="https://i.stack.imgur.com/mCWTX.jpg" alt="enter image description here"></p>
  
  <p><strong>Update my own answer and this question shall close</strong></p>
  
  <pre><code>// Pass the whole dataGridView1 into method and access the value through row count.
  DoSomethingMethod(DataGridView dataGridView1)
  {
      for (int rows = 0; rows &lt; dataGridView1.Rows.Count; rows++)
      {
          double myX = Convert.ToDouble(dataGridView1.Rows[rows].Cells["Latt"].Value);
          double myY = Convert.ToDouble(dataGridView1.Rows[rows].Cells["Long"].Value);
      }
  }
  </code></pre>