DataGridView 中發生以下異常: System.Exception: 是 不是 Decimal 的有效值。 ---> System.FormatException: 輸入字符串的格式不正確。


其實之前我自己是沒測出這個問題的,但是一放到測試的手上就出來了,原因我知道在哪里改輸什么東西,但是人家不知道啊。報錯如下:

 

 

 

---------------------------
“DataGridView 默認錯誤”對話框
---------------------------
DataGridView 中發生以下異常:

System.Exception: 是 不是 Decimal 的有效值。 ---> System.FormatException: 輸入字符串的格式不正確。
   在 System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
   在 System.Number.ParseDecimal(String value, NumberStyles options, NumberFormatInfo numfmt)
   在 System.ComponentModel.DecimalConverter.FromString(String value, NumberFormatInfo formatInfo)
   在 System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
   --- 內部異常堆棧跟蹤的結尾 ---
   在 System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
   在 System.ComponentModel.TypeConverter.ConvertFrom(Object value)
   在 System.Windows.Forms.DataGridView.DataGridViewDataConnection.PushValue(Int32 boundColumnIndex, Int32 columnIndex, Int32 rowIndex, Object value)

要替換此默認對話框,請處理 DataError 事件。
---------------------------
確定   
---------------------------

解決方法,注冊一個DGV_DataError事件就可以。

private void DGV_DataError(object sender, DataGridViewDataErrorEventArgs e)
{

  //可以不執行代碼哦

}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM