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

解决方案 »

  1.   

    try catch 后throw自己定义的Exception
      

  2.   

    try
    {
       //your code
    }
    catch(Exception err)
    {
        throw new Exception("YourErr");
    }
      

  3.   

    在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("你输入的格式不正确,必须为数字!");
            }