我有这段代码(gridview,cellvaluechanged 事件):
private void gv1_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
{
string value1 = Convert.ToString(gv1.GetRowCellValue(gv1.FocusedRowHandle, "unitvalue"));
object cellValue = Convert.ToUInt32(value1) * Convert.ToInt32(days_worked);
gv1.SetRowCellValue(gv1.FocusedRowHandle, "totalvalue", cellValue);
}
“days_worked”是从标签控件中获取的值,单元格的值不会改变, 出现以下错误:“System.StackOverflowException”类型的未处理异常发生在 mscorlib.dll 中
“totalvalue”是我数据库的一列
请帮忙,谢谢!
最佳答案
如文档中所述
The CellValueChanged event fires in response to a cell's value being changed. The list below gives the possible reasons for this event being raised:
- An end-user has closed an in-place editor after changing the editor's value.
- A cell's value has been changed using the methods provided by Views. For instance, the SetRowCellValue method can be used for this purpose.
所以你需要按照建议文档更改你的代码
private void gv1_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
{
if (e.Column.Caption != "totalvalue") return; // if event in fire from cells in column "totalvalue"
string value1 = Convert.ToString(gv1.GetRowCellValue(gv1.FocusedRowHandle, "unitvalue"));
object cellValue = Convert.ToUInt32(value1) * Convert.ToInt32(days_worked);
gv1.SetRowCellValue(gv1.FocusedRowHandle, "totalvalue", cellValue);
}
关于c# - DevExpress - 设置单元格值 - mscorlib.dll 中发生类型为 'System.StackOverflowException' 的未处理异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21449236/