For me the Feature Browser IDataErrorInfo example under Themes and Styles doesn't help a bit. It's way too complicated for me with absolutely no discussion on how to implement it. I've searched the forums here and am still blank on how to do this. I'm new to WFP to begin with so I need help here.
Is there a simple, commented example of how to implement IDataErrorInfo for the XAMDataGrid that a newby can follow?
1) highlight and icon for fields requiring text input (any length) without using any editors, or if necessary, using the text editor -- this would be just for the data grid itself at the UI level
2) same scenario where the business object the grid is bound to implements IDataErrorInfo.
Please don't point me to partial posts with scanty information because I've tried them. I even copied the styles in from the Feature Browser sample, but no errors trigger and I cannot see where in that sample, in the XAML, or the code behind, where in the heck the control is told that an amount has to be greater than zero etc. What is triggering those?
Frustrated after several hours of trying...
After experimenting, I discovered you can combine client-side validation in the UI for the XAMDataGrid with business-layer IDataErrorInfo by performing your client-side validation in the XAMDataGrid's RecordUpdating event handler as shown in the following example:
private void dgSampleProgrammes_RecordUpdating(object sender, RecordUpdatingEventArgs e) { bool IsValid = true; if (e.Record is DataRecord) { DataRecord dr = e.Record as DataRecord; foreach (Cell cell in dr.Cells)
if (cell.Value == null || cell.Value == "") { //Set the data error object by raising the property changed event cell.Value = ""; IsValid = false; break; }
if (!IsValid) { e.Action = Infragistics.Windows.DataPresenter.RecordUpdatingAction.CancelUpdateRetainChanges; }
else { e.Action = RecordUpdatingAction.ProceedWithUpdate; } } }
Notice that if the cell value is null, I'm setting the cell value to "";this triggers the property change which will in turn call the field validation and raise the IDataErrorInfo error notification. Notice I'm not just testing for a null value, because if the user tries to click off the newly entered record in the datagrid, the value will now be "" and will pass the validation in the above method if the only test is for a null value!
The benefit of this approach is that you can have your client side validation any way you want, and still use the same IDataErrorInfo implementation you added to your business class.
Sorry about the formatting of this messsage; there are no font controls to use here...
A problem with validating data at the property level is that bound properties only change when something changes their values. For example, when you tab across a null field, the value never gets set, hence the property never gets changed, subsequently, the property validation method never gets called.
In the posted example, you can tab through the first text field, enter a positive value and the validation completely misses the not-entered field. In this example you can compensate by also calling this.ValidateName(false); in the Quantity Set property, however that will also get missed if you don't enter a quantity. To overcome this situation you have to validate right in the datagrid, so now you have two layers of validation.
I suppose IDataErrorInfo is still good for business-layer validation once the required fields have been validated as far as entry is concerned.
I removed the theme and the error persists. Even removing the mask, which gets rid of the error, I can only enter 1 record; it never 'commits' the record so I can add a new one. No errors are shown. Is this supposed to happen?
I am not sure why this happens on your end. I am not seeing this behavior. This could be because there is a style for the XamNumericEditor outside the XamDataGrid's resources and the theme is set. Try with removing the theme or moving the style in the XDG"s resources.
ok, I removed the mak in the resource and I'm able to run the project.
<Window.Resources>
<Style TargetType="{x:Type igEditors:XamNumericEditor}">
<Setter Property="Mask" Value="nnn"/>
</Style>
Very easy to follow, thanks a bunch.