I have a situation where I dynamically build columns and that includes whether a column is required to have data or not. This is in metadata in another table, so the underlining table has no requirements for data. It is all created at runtime by reading the configuration. Make sense? So in following some examples, I created a style for required fields that turns the border read if the value is NULL, and that works fine in showing the red border:
In code creating column:
field.Settings.EditorStyle = (Style)FindResource("RequiredFieldStyle");
In XAML
<Style x:Key="RequiredFieldStyle" TargetType="{x:Type igEditors:ValueEditor}"> <Style.Setters> <Setter Property="ValueConstraint"> <Setter.Value> <igEditors:ValueConstraint Nullable="False" /> </Setter.Value> </Setter> <Setter Property="InvalidValueBehavior" Value="RetainValue" /> </Style.Setters> <Style.Triggers> <Trigger Property="IsValueValid" Value="false"> <Trigger.Setters> <Setter Property="BorderBrush" Value="Red" /> </Trigger.Setters> </Trigger> </Style.Triggers> </Style>
This works fine for showing the red border if a value isn't set. However, nothing really enforces the record from being saved because there are no "true" errors in the record. So I am trying to figure out how to catch something on the RecordUpdating, maybe look through each cell, check the EditorStyle, if it is the RequiredStyle, see if it has a value, and if it doesn't not save. But EditorStyle is always null.
So my question is, is this is the best way of doing this? How can I stop the record from being saved when I really can't impliment IDataError and build all the columns dynamically and set dynamic validation requirements on fields?
Hello,
It has been a while since you have made your post, in case you still need support I will be glad to assist you further. I suppose the other community members can benefit from this answer as well. I have been looking through your post and I suggest you use set the UpdateMode Property of the XamDataGrid to OnUpdate, which will make the Records to update only when a command is executed. You can see here what are the available commands you can use if the Record should update:
http://help.infragistics.com/NetAdvantage/WPF/2011.1/CLR4.0/?page=InfragisticsWPF4.DataPresenter.v11.1~Infragistics.Windows.DataPresenter.DataPresenterCommands_members.html
Feel free to write me if you have further questions.