How to handle exception from underlying dataset of an Ultrawingrid (winforms)
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 m开发者_JAVA技巧essage 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");
}
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;
}
精彩评论