I've just started looking at this grid last week. If you are editing within the grid itself, the below methods seem to work, however if editing outside the grid I haven't had any success with data triggers on the isvalid property. The grid doesn't update, I have to scroll the row out of view, then back in view for the new background/border to show up. Frustrating. I have a forum link on this problem here http://forums.infragistics.com/forums/p/14994/55821.aspx#55821
private void userGrid_RecordUpdating(object sender, Infragistics.Windows.DataPresenter.Events.RecordUpdatingEventArgs e) { if (((IDataErrorInfo)((Object)((Infragistics.Windows.DataPresenter.DataRecord)e.Record).DataItem)).Error.Length > 0)
e.Action = Infragistics.Windows.DataPresenter.
RecordUpdatingAction.CancelUpdateRetainChanges;}
private void userGrid_EditModeEnded(object sender, Infragistics.Windows.DataPresenter.Events.EditModeEndedEventArgs e) { IDataErrorInfo obj = (IDataErrorInfo)((Object)((Infragistics.Windows.DataPresenter.Cell)e.Cell).Record.DataItem); string errorMessage = obj.Error; if (errorMessage.Length > 0) {e.Editor.BorderBrush =
Brushes.Red; if (e.Editor.ToolTip != null)e.Editor.Tag = e.Editor.ToolTip;
e.Editor.ToolTip = errorMessage;
}
else { if (e.Editor.Tag != null) {e.Editor.ToolTip = e.Editor.Tag;
e.Editor.Tag =
null;}
elsee.Editor.ToolTip =
null;e.Editor.BorderBrush =
null;}
}
hmmm,
I wonder if throwing a property changed event for IsValid from the ListChanged event might work.
In Silverlight we solved the problem with validation/authorization by creating our own column types that incorporate a PropertyStatus control into each cell. PropertyStatus is far more powerful than the standard WPF validation, and it provides authorization and busy notification, so it was important that the grid have this option.
I wonder if the WPF grid isn't designed in a similar manner, where you can create custom column types to render cells as you desire?
PropertyStatus binds to the same business object property as the
“target control”. So if you bind a TextBox to a FirstName property,
you’d bind PropertyStatus to that same FirstName property. It then uses
PropertyChanged to know to do its work.
Rocky
Are you saying that if there are two items in the collection
with the same value for same property, then each item is invalid?
Sergey Barskiy
Principal Consultant
office: 678.405.0687 |
mobile: 404.388.1899
Magenic ®
Microsoft Worldwide Partner of the Year | Custom
Development Solutions, Technical Innovation
From: ajj3085
[mailto:cslanet@lhotka.net]
Sent: Wednesday, October 22, 2008 12:05 PM
To: Sergey Barskiy
Subject: Re: [CSLA .NET] RE: XamDataGrid
Ok.. I'm not sure what to do at this point. My problem
is that an existing item in the collection can become invalid when another item
is added to the collection with the same value... so there's no PropertyChanged.
I'll have to do more research.. maybe binding to brokenrules to trigger an
event handler.
I think you should be able to use Property Status in this
scenario as long as you raise Property Changed event as part of your rules run,
which would force property status to refresh. I think this might just
work
Sergey Barskiy
Principal Consultant
office: 678.405.0687 |
mobile: 404.388.1899
Microsoft Worldwide Partner of the Year | Custom
Development Solutions, Technical Innovation
From: ajj3085
[mailto:cslanet@lhotka.net]
Sent: Wednesday, October 22, 2008 2:13 PM
To: Sergey Barskiy
Subject: Re: [CSLA .NET] RE: RE: XamDataGrid
Yes, that's correct.
This is done to support the "new row" on the grid. The row gets
added, which creates the BO with the default value, so I can't do the check
there. Instead, the check occurs when the property value is changed (via
normal Csla validation). In addition, the BLB overrides OnChildChanged,
and asks all OTHER rows to re-run their rule check.
The user could correct the data by then changing either of the instances, which
should cause both to validate. The user could also delete one of the rows which
will cause everything to become valid again.
I'm not sure what other way to go without breaking out of standard Csla
validation (allow invalid data, but flag it).
A business rule is just a method – you can make it as
complex as you’d like. So you sure could have your rule check some other
condition to decide whether it should do its real check or not.
Rocky
The only suggestion that I have right now is to move the rule
from ListChanged into each item. Each item can check all other items in
the same list, return false from rule if duplicate found, set a static Boolean flag
(like validation in progress), then call all its piers to do the same. Each
of those will just check itself and not call the piers based on static
flag. The item that initiated the check to begin with will reset the static
flag and return true/false from the rule.
Does this make sense?
Sergey Barskiy
Principal Consultant
office: 678.405.0687 |
mobile: 404.388.1899
Microsoft Worldwide Partner of the Year | Custom
Development Solutions, Technical Innovation
From: ajj3085
[mailto:cslanet@lhotka.net]
Sent: Wednesday, October 22, 2008 5:00 PM
To: Sergey Barskiy
Subject: Re: [CSLA .NET] RE: RE: RE: XamDataGrid
Well, I've hit a snag. Raising PropertyChanged causes
the list to again ask other instances to check their Location property, which
causes a StackOverflowException.
Is there any way to code a business rule such that it will only perform an
action if some other condition is not met?
Copyright (c) Marimer LLC