XamDataGrid

XamDataGrid

Old forum URL: forums.lhotka.net/forums/t/5639.aspx


ajj3085 posted on Tuesday, October 21, 2008

HI,

I'm trying to use a XamDataGrid to display a BLB subclass, PartLocations.

The list displays fine, but I'm trying to get a red border around a cell that has a data error (the grid doesn't support this just yet).

Each PartLocation in the collection has a rule that ensures it is unique.  When the Location property is changed, it runs the rule fine.  Also, the PartLocations overrides OnChildChanged, and asks each instance to also run it's rule checks.  The result should be that if there's a duplicate, all duplicate rows will be given a red border.

The rules seem to run fine, but I'm having trouble figuring out how to get the cell with the error to draw with a red border.  Anyone else using this grid?

Thanks
Andy

Curelom replied on Tuesday, October 21, 2008

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;

} else

e.Editor.ToolTip = null;

e.Editor.BorderBrush = null;

}

}

Curelom replied on Tuesday, October 21, 2008

When the IsValid property changes, does it send a property changed event?

ajj3085 replied on Tuesday, October 21, 2008

No, it doesn't look like that happens.  I think that's the problem I'm hitting; the other item in the collection needs to notify something that it's no longer valid, so the cell can have it's border updated.

What I tried doing was hooking an event to each PartLocation's BrokenRulesCollection ListChanged event... but the problem there was I couldn't get to the cell / value editor for the record... so I couldn't update anything!

Curelom replied on Tuesday, October 21, 2008

hmmm,

I wonder if throwing a property changed event for IsValid from the ListChanged event might work.

ajj3085 replied on Tuesday, October 21, 2008

Possibly... but this kind of "bubbling" is what caused problems in Winforms, so I'd be careful.  I've moved on to getting other parts of my control working, but I will have to come back to this issue. 

It's frustrating that I couldn't figure out how to get to the proper cell using the DataRecord.. that's the only thing that kept from from solving this problem.

RockfordLhotka replied on Tuesday, October 21, 2008

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?

ajj3085 replied on Wednesday, October 22, 2008

Hmm... I can look into that.  You can tell it the editor to use, so maybe I can plug in a custom editor.  Does simply running a rule, which causes IsValid to change value, cause some kind of notification that PropertyStatus picks up on? 

RockfordLhotka replied on Wednesday, October 22, 2008

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

ajj3085 replied on Wednesday, October 22, 2008

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.

sergeyb replied on Wednesday, October 22, 2008

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.


ajj3085 replied on Wednesday, October 22, 2008

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).

sergeyb replied on Wednesday, October 22, 2008

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

cid:_2_0648EA840648E85C001BBCB886257279
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).


ajj3085 replied on Wednesday, October 22, 2008

Ok, I wasn't sure if that was a valid thing to do anymore.  I'll try it and find out.

ajj3085 replied on Wednesday, October 22, 2008

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?

RockfordLhotka replied on Wednesday, October 22, 2008

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

sergeyb replied on Wednesday, October 22, 2008

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

cid:_2_0648EA840648E85C001BBCB886257279
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