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());
            }
        }

2个回答

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;
又修改了单元格

所以就堆栈溢出了

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐