2011-08-25 29 views
2

我有一个UltraWinGrid及其背后的数据集。在数据表的Row_Changing事件处理程序中,我会对数据进行一些检查,并在发生异常时发出异常。我想在我的应用程序中显示此异常的消息。但是,UltraGrid似乎捕获异常并显示它自己的消息框,但有一个例外。如何防止显示消息框,并在应用程序中捕获该错误?如何处理Ultrawingrid(winforms)底层数据集的异常

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"); 
} 

回答

2

我解决了这个问题,但我想我会创建这个问题(因为我已经输入了它)。

你需要处理的UltraGrid的错误事件,并设置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; 
}