Hello,
I've a simple XamGrid with a bounded items source. I want to validate the bounded data and highlight the column correspondingly.The user should now correct these data.
I've looked into the validation part of the documentation but this only refers to the validation of data, the user enters into the specific controls at runtime.
How can I achieve this?
Hi,
The XamGrid is using TextBlock controls to render cell content when not in edit mode and since the TextBlock does not have a border it is not possible to show existing errors on initial load. You could try and create a custom template when not in edit mode to use a more complex element but that will add some performance impact.
Or you could use the XamDataGrid control if the application is WPF only. The grid supports displaying errors on initial load since the cell presenter template there is different.
Please let me know if you have any other questions.
Thanks,
Slavi
Thanks for the answer,
with the XamDataGrid, I can easily define ValueConstraints.
But this errors are only shown in the specific cell.
My goal is, to have a separate column with an icon,displayed when the row contains any errors. So, the user can filter or search after errors.
I found the properties Host.DataError, Host.HasDataError in the documentation butI can't bring that together.
Perhaps someone has done that before?
Hi
I am not sure I follow what exactly should be placed in that error column because multiple cells may have errors. My assumption is that the idea is to show the record error or some concatenated error for all the cells contacting errors. I created a sample application that uses Unbound field that uses a field in the data source that reruns the errors for the entire record. That way users can filter based on the errors. The property may be implemented to rerun a more detailed information.
Please let me know if this is what you were looking for or if you have any other questions.
Thank you so much!
Actually, it is more simple. The additional column should only indicate, if there is an error in any field or not.So that the user look for these indicators (or filter) and than he see the single cell errors perhaps with a red square...
I can build up on your example.
I will post my modified example for other user...
Oh, there is one more problem...
The ValueConstraint doesn't make the Icon visible.
This is because the HasDataError is saved in the object but the result of the ValueConstraint not.
I'ive created a new class without implementing IDataErrorInfo to demonstrate it:
public class MyClass { public decimal Price { get; set; }}
Currently, I have no idea to solve that. Is there a container object for constraint errors per row or something like that?
PS:I only want to have one place to define validating... I think ValueConstraints can be implemented easier
I am glad you managed to resolve your issue. Thanks for sharing it.
-Slavi
finally, I found a solution.
It's a bit simpler than yours.
I've attached it, if someone need to resolve the same problem!
Thanks again....
The main issue is that you have more than one column that needs to be validated. In order to say that a record Has Errors you need to check all Price cells for errors. Also you need to update this Has Erorrs whenever a price field gets modified. I modified your class to include a dictionary for the errors and added HasErrors property that checks the count of the errors to evaluate if a record or MyClass object is valid. The validation is using the PriceValidationRule so the logic is reused. However the implementation is almost the same as implementing IDataErrorInfo Interface. I modified your sample so you can take a look. If your requirements do not allow modifying the business object to include other properties it may not be possible to achieve the behavior you describe.
Let me know if this works for you or if you have any other questions.
let me try to explain it one more time.
At First, I prefer to use a XamGrid because of performance and features...
The point is, that I don't want to implement the IDEI. That's because there are already some ValidationRules in my company,which we use in many projects. For example to validate the price in many ways.
But there is no way (I know), to use ValidationRules with the fields or row on a XamGrid.So I want to use the ConditionalFormat feature to achieve this.
I've created an own FormatRule, called: ValidationFormatRule.Here, I can specify a style to apply, if the result of the validation rule, set on the ValidationFormatRule, is not valid.
But for the user, it is very unhandy to scroll through 10000 rows, to see, if there are any errors left.
That's why I need an additional column (Name it ErrorColumn), that indicates, there is one or more errors in this row and,the important thing, he can set a filter on this column, so he can see only the rows, which have errors.
The problem I have now is, the ErrorColumn need to know, If there is any error or conditional format on any cell in the current row.Furthermore, the ErrorColumn needs different values, if there are errors or not. Because of the filter function.
In the IDEI scenario, there is a property on the business object, that indicates that (HasDataErrors).
This is the connection I am looking for.
Here is the example, with the additional classes, but the logic on the ErrorColumn is missing!
I am sorry but I do not think I fallow what the ide is any more. I hope this information is helpful:
The HasDataError and the DataError properties are meant to show the information provided by the IDataErrorInfo interface implementation. The CellValuePresenters that are used to represent cell content have the additional logic to populate the DataError with the ValueConstraint error messages. The Record level error can be set when implementing the IDEI interface where user need to decide when to set it and based on what criteria.
If that error column will just contain icon to indicate and error isn't this the same as the already existing functionality of the grid to show error icons in cells with errors/validation rules ?
If the idea is to use a custom icon here is an example how this can be done: http://es.infragistics.com/products/wpf/sample/data-grid/data-error-styling
Thanks,Slavi