我在两个不同的数据网格中有两个数据,我想从行中获取值,以便我依靠欧氏距离公式。我可以获取第二个 datagridview 中的值,但无法获取第一个 datagridview 中的数据。
我试图写 foreach,但我仍然在那里
foreach (DataGridViewRow row1 in dataGridView1.Rows)
{
foreach (DataGridViewRow row in dataGridView2.Rows)
{
double NilaiPixelGrid1 = Convert.ToDouble(row1.Cells[2].Value.ToString());
double NilaiRedGrid1 = Convert.ToDouble(row1.Cells[3].Value.ToString());
double NilaiGreenGrid1 = Convert.ToDouble(row1.Cells[4].Value.ToString());
double NilaiBlueGrid1 = Convert.ToDouble(row1.Cells[5].Value.ToString());
double NilaiPixel = Convert.ToDouble(row.Cells[2].Value.ToString());
double NilaiRed = Convert.ToDouble(row.Cells[3].Value.ToString());
double NilaiGreen = Convert.ToDouble(row.Cells[4].Value.ToString());
double NilaiBlue = Convert.ToDouble(row.Cells[5].Value.ToString());
double dist = Math.Pow((NilaiPixelGrid1 - NilaiPixel), 2) +
Math.Pow((NilaiRedGrid1 - NilaiRed), 2) +
Math.Pow((NilaiGreenGrid1 - NilaiGreen), 2) +
Math.Pow((NilaiBlueGrid1 - NilaiBlue), 2);
}
}
System.NullReferenceException:“未将对象引用设置为对象的实例。”
梦里花落0921
凤凰求蛊
回首忆惘然
随时随地看视频慕课网APP
相关分类