2014-01-30 63 views
2

我有此代碼(gridview的,cellvaluechanged事件):的DevExpress - 設置單元格值 - 類型 'System.StackOverflowException' 的未處理的異常出現在mscorlib.dll

 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

「總價值」是我的數據庫列

請幫忙, 謝謝!

+0

我想'SetRowCellValue'加薪事件中'CellValueChanged',所以你需要或其他活動,或使用另一個函數進行設置值 – Grundy

+0

不知道這個,用相同的3天,OMG – Vigo

+0

你用winforms?的WebForms? – Grundy

回答

2

如文檔說

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); 
} 
+2

+1 - Stackoverflow的原因是在'CellValueChanged'事件中設置了一個單元格值 - 這會觸發事件再次發生 - 所以它會進入一個「循環」,直到你得到你的例外。 –

+0

感謝這麼多人,ü拯救了我的生活,感謝幫助社區 – Vigo

相關問題