Hi All
I want to check my UltraGrid has error or not, and set e.Cancel accordingly. but I have no idea how to do this.
my form submit button calls form.validateChildren(), but i dont know where to set the e.Cancel.
i use objects as datasource, and my object class implemented IDataErrorInfo, and my UltraGrid is showing the error icon accordingly.
this is logically what i want
UltraGrid_validating(object sender, CancelEventArg e){
if(this.UltraGrid.hasError){
e.Cancel = true;
errorMessageList.Add( this.UltraGrid.ErrorMessage);
} else{e.Cancel = false;}
}
Regards
Bryan
Hi Bryan,
Calling UpdateData on the grid will commit all changes from the grid to the underlying data source. At this point, your IDataErrorInfo would presumably be up-to-date. Then you would have to loop through the rows of your data source to determine if there are any errors. I could be wrong, but I don't think IDataErrorInfo has any events on it, it just has properties that return error information.
Mike Saltzman"] So you would have to loop through the rows in your data source and check for errors using the IDataErrorInfo interface.
So you would have to loop through the rows in your data source and check for errors using the IDataErrorInfo interface.
how do i trigger IDataErrorInfo in the code? could you provide a few line of example codes? Currently, the IDataErrorInfo is trigger by the datasource or the grid autoly, i think.
Mike Saltzman"] So what you will have to do is call the grid's UpdateData method. This will force the grid to commit any pending changes to the data source and then you can check for errors and decide what to do.
So what you will have to do is call the grid's UpdateData method. This will force the grid to commit any pending changes to the data source and then you can check for errors and decide what to do.
But do it still need to loop throught the records after the UpdateData? Is there any event will get trigger when validation fail?
BR
Okay, I think I understand the issue.
The grid doesn't expose any of the errors from the data source, since this would be redundant. So you would have to loop through the rows in your data source and check for errors using the IDataErrorInfo interface.
Of course, in the grid's Validating event, you cannot be sure that the grid doesn't still have some pending changes that have not yet been written to the data source. So what you will have to do is call the grid's UpdateData method. This will force the grid to commit any pending changes to the data source and then you can check for errors and decide what to do.
Hi Mike,
Mike Saltzman"]If you click on a button on your form then the grid will lose focus and it will save any pending changes to the DataSource. If the DataSource support IDataErrorInfo, then the grid will display the errors at this point - after the DataSource has been updated.
Yes , the error icons do show on the grid. What the submit button do is re-validate the controls in the forms. Each control's validating event will be fire again, including the grid_validating event.
My problem is my ultrawingrid validation is done by the datasource's model's IDataErrorInfo members (i am using object data source), not the grid_validating event, hence, I need to check has the grid contain any error or not. How do I check has the grid contain any errors in the grid's validating event??
I'm not sure I understand exactly what you are trying to do. What are you trying to cancel?
If you click on a button on your form then the grid will lose focus and it will save any pending changes to the DataSource. If the DataSource support IDataErrorInfo, then the grid will display the errors at this point - after the DataSource has been updated.
So what part of this process are you trying to cancel? You cannot check for errors and then cancel the writing of the data to to the DataSource, since the errors don't occur until after the DataSource is updated.