日期:2014-05-20  浏览次数:20821 次

請教:如何取代系統錯誤ExceptionMessage?
RT,我設置Datagridview為數值格式,輸入非法字符時系統會提示錯誤,如何取代系統錯誤訊息,自定錯誤訊息呢?

------解决方案--------------------
try catch 后throw自己定义的Exception
------解决方案--------------------
try
{
//your code
}
catch(Exception err)
{
throw new Exception( "YourErr ");
}
------解决方案--------------------
楼上的都说了。
------解决方案--------------------
在DataError事件中写
private void Datagridview_DataError(object sender, DataGridViewDataErrorEventArgs e)
{
if (e.ColumnIndex == 4)
Utility.ShowInformation( "你输入的格式不正确,必须为数字! ");
if (e.ColumnIndex == 5)
Utility.ShowInformation( "你输入的格式不正确,必须为数字! ");
if (e.ColumnIndex == 6)
Utility.ShowInformation( "你输入的格式不正确,必须为数字! ");
if (e.ColumnIndex == 7)
Utility.ShowInformation( "你输入的格式不正确,必须为数字! ");
}