我有一个链接到 DGV 的上下文菜单条。单击 DGV 中的单元格时,它将打开上下文菜单条,我可以单击“plotStripMenuItem”打开一个表单(formPlot),该表单基本上从文本文件中读取数据并绘制图形并计算一些统计数据返回(一旦 formPlot 关闭)到 DGV 的先前单击的行。
为此,我在打开 formPlot 之前使用“int clickedRow”存储单击的行号,并在关闭 formPlot 后使用它来更新 DGV。
private void plotToolStripMenuItem_Click(object sender, EventArgs e)
{
//get the row number which was clicked
string strClickedRow = DGVLeft.CurrentCellAddress.Y.ToString();
int clickedRow = Convert.ToInt16(strClickedRow);
FormPlot formPlot = new FormPlot(strLot, pathLD);
formPlot.ShowDialog();
DGVLeft.Rows[clickedRow].Cells[0].Value = formPlot.columnA;
DGVLeft.Rows[clickedRow].Cells[1].Value = formPlot.ColumnB;
DGVLeft.Rows[clickedRow].Cells[2].Value = formPlot.columnC;
DGVLeft.Rows[clickedRow].Cells[3].Value = formPlot.columnD;
}
大多数情况下,这按预期工作。但我注意到它偶尔不会更新在我打开 formPlot 之前单击的 DGV 单元格。相反,它更新了第 0 行!
例如,我单击了第 7 行,但从 formPlot 返回后,DGV 第 0 行的值是更新的值。不是 DGV 行号 7 的值。
对我来说,现在第 0 行将成为更新的行,因为我单击第 7 行并将其存储在一个变量中。
我在这里错过了什么吗?