【发布时间】:2010-12-02 03:42:04
【问题描述】:
我有一个 .NET Windows 应用程序。
我有一个DataGridView,其中有几行。我添加了一个包含按钮的列,以允许用户编辑一行。这会弹出一个新表单/对话框 - 我的编辑表单。
// Add a CellClick handler to handle clicks in the button column.
dgv.CellClick += new DataGridViewCellEventHandler(dgv_CellClick);
触发它的代码是:
private void dgv_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == buttonCell)
{
// Get the id number
int number = Convert.ToInt32(dgv.Rows[e.RowIndex].Cells[0].Value);
EditForm edit = new EditForm(number);
edit.ShowDialog();
}
}
问题
我的编辑表单显示(正确)。我进行更改,然后关闭表单。然后它再次加载!它对我的网格中相同数量的行执行此操作。 IE。它为 DataGrid 中的每一行触发一次上述代码。
如何防止这种情况发生?有没有更优雅的解决方案?
【问题讨论】:
标签: .net winforms datagridview