问题描述
- datagridview直接给某个单元格赋值结果出现死循环
-
“System.StackOverflowException”类型的未经处理的异常在 System.Windows.Forms.dll 中发生private void dgvLCA_CellValueChanged(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex != -1) { this.dgvLCA.Rows[e.RowIndex].Cells[5].Value = this.dgvLCA.Rows[e.RowIndex].Cells[2].Value; MessageBox.Show(this.dgvLCA.Rows[e.RowIndex].Cells[4].Value.ToString()); } }
解决方案
bool b = false;
private void dgvLCA_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex != -1 && !b)
{
b = true;
this.dgvLCA.Rows[e.RowIndex].Cells[5].Value = this.dgvLCA.Rows[e.RowIndex].Cells[2].Value;
MessageBox.Show(this.dgvLCA.Rows[e.RowIndex].Cells[4].Value.ToString());
b = false;
}
}
解决方案二:
dgvLCA_CellValueChanged
在单元格修改的时候触发
this.dgvLCA.Rows[e.RowIndex].Cells[5].Value = this.dgvLCA.Rows[e.RowIndex].Cells[2].Value;
又修改了单元格
所以就堆栈溢出了
时间: 2024-10-01 08:35:42