如何处理 Ultrawingrid (winforms) 底层数据集的异常

发布于 2024-12-01 04:58:46 字数 369 浏览 5 评论 0原文

我有一个 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");
}

I have an UltraWinGrid with a dataset behind it. In the datatable's Row_Changing event handler, I do some checking of the data and throw an exception if it is invalid. I want to display a message for this exception within my application. However, the UltraGrid seems to catch the exception and display it's own message box with the exception. How can I prevent the message box from being displayed, and catch that error within my application?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清醇 2024-12-08 04:58:47

我解决了,但我想无论如何我都会提出这个问题(因为我已经把它打出来了)。

您需要处理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;
}

I worked it out, but I thought I'd create this question anyway (since I have already typed it out).

You need to handle the Error event of the UltraGrid and set e.Cancel to true to prevent the dialog box from popping up:

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文