経度と緯度の値を含む dataGridView があります。
値を に渡して使用する必要がありますDoSomethingMethod()
。
私はdataGridViewに慣れていないので、dataGridViewからすべての値をコピーして処理しますList<>
以下は、dataGridView内のデータを操作する私のコードです
Public Main()
{
List<double> lst_Long = new List<double>();
List<double> lst_Latt = new List<double>();
for (int rows = 0; rows < 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<double> lst_long, List<double> lst_latt, int ColumnCount, int RowCount)
{
for (int iColumn = 0; iColumn < ColumnCount; iColumn++)
{
for (int iRow = 0; iRow < 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 );
}
}
}
Columns["Long"]
dataGridView からセル値を直接使用して取得し、 dataGridViewColumns["Latt"]
からリストに値をコピーせずに同様のことを行う他の方法があるかどうかを尋ねたいと思いますか?
ありがとう〜
更新:以下は私のDGVテーブルです(データはランダムであり、実際のものではありません)
自分の回答を更新すると、この質問は終了します
// Pass the whole dataGridView1 into method and access the value through row count.
DoSomethingMethod(DataGridView dataGridView1)
{
for (int rows = 0; rows < dataGridView1.Rows.Count; rows++)
{
double myX = Convert.ToDouble(dataGridView1.Rows[rows].Cells["Latt"].Value);
double myY = Convert.ToDouble(dataGridView1.Rows[rows].Cells["Long"].Value);
}
}