我有一个UltraWinGrid,后面有一个数据集。在datatable的Row_Changing事件处理程序中,我会对数据进行一些检查,如果数据无效则抛出异常。我想在我的应用程序中显示此异常的消息。但是,UltraGrid似乎捕获异常并显示它自己的消息框,但有异常。如何防止显示消息框,并在我的应用程序中捕获该错误?
private static void Row_Changing( object sender, DataRowChangeEventArgs e )
{
if( <some logic to test the row values>)
throw new Exception("you can't do that");
}
答案 0 :(得分:2)
我把它解决了,但我认为无论如何我都会创建这个问题(因为我已经输入了它)。
您需要处理UltraGrid的Error事件并将e.Cancel设置为true以防止弹出对话框:
public Form1()
{
...
this.ultraGrid1.Error += new Infragistics.Win.UltraWinGrid.ErrorEventHandler(ultraGrid1_Error);
}
void ultraGrid1_Error(object sender, Infragistics.Win.UltraWinGrid.ErrorEventArgs e)
{
//< deal with the error here>
// set Cancel to true to prevent the dialog box from showing.
e.Cancel = true;
}