2

我有一个 UltraWinGrid,后面有一个数据集。在数据表的 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");
}
4

1 回答 1

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;
}
于 2011-08-25T04:27:30.790 回答