WPFToolkit DataGrid and EditableRootList Update 2nd time

WPFToolkit DataGrid and EditableRootList Update 2nd time

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


vschuhma posted on Friday, October 17, 2008

Hi all,

I am trying to get the new Wpf datagrid to work with an EditableRootList. When I update one of my items in the collection through editing a cell in the grid everything works fine first time changes are made. I can see the events being fired in the grid and Save is called on the item. The properties passed in are the new ones after editing.

Second time, same cell, same picture although the item passed seems to be the old one. IsDirty not checked, properties not modified. Of course the Save is ignored in BusinessBase.

Looks like the Grid is not replacing the references after the first update. However the UI is showing the correct values after the modifications although they are never modified in the DB. I am using a StaticResource and the CslaDataProvider. Csla Version 3.5.1 with VS 2008 Express C# :Net 3.5 Sp1 

Am I missing something or is it really an issue with the new DataGrid?

Best Regards

Volker

cclark replied on Friday, October 17, 2008

I believe you are right, this is the same issue I am encountering, although I am not using the DataGrid (both use the System.Windows.Data.BindingListCollectionView).

There appear to be a couple of issues going on, the first is that the BindingListCollectionView is holding a reference to the old object, the second is that CSLA has a problem where IEditableObject.BeginEdit is essentially ignored because Csla.Core.BusinessBase.BindingEdit is true even though the object is not in an edit state. I don't know about your framework, but we require the object to be in Edit mode or else we ignore the setter (and in debug mode have a Debug.Assert to alert the devs/testers).

At this moment, we belive the first problem is really for Microsoft. The second issue may be a bug in CSLA (or rather it better handle the odd behaviours of the MS code).

We're hoping to know by the end of the day and I will keep you posted.

cclark replied on Friday, October 17, 2008

This fixed one of my problems, see if it fixes yours as well:

In Csla.Core.BusinessBase.ApplyEdit()

Move BindingEdit = false to before the AcceptChanges call, so it should look like this:

public void ApplyEdit()
{
   _neverCommitted =
false;
   BindingEdit =
false;
   AcceptChanges(
this.EditLevel - 1);
   //BindingEdit = false;
}

The reason all this is occuring gets a little involved. If it works for you as well I will try to post the writeup this weekend.

RockfordLhotka replied on Friday, October 17, 2008

The question then becomes whether this change breaks Windows Forms behaviors? Windows Forms is SO picky, it seems likely that this may cause problems - though perhaps we'll get lucky?

There is the ApplicationContext.PropertyChangedMode setting - which I now suspect is poorly named. It is used to change the PropertyChanged behavior to work with either Windows Forms or WPF, and may end up being the control flag for other differing behaviors...

vschuhma replied on Saturday, October 18, 2008

just made the change you suggested.

It still does not work. I still get back the wrong "old" object from the UI after one succesful update on a particular row. On subsequent changes to this item in the Grid it will always point  to that object and keeps passing it back to me though the UI shows the updated values. The BusinessBase is not marked dirty and fields have the old value of the one change it does propagate to the DB.

I assume it is a MS issues with the collection view. Sorry but the suggested workaround does not work in my case. Propably have to invalidate the whole ERLB and sort of rebind.

Atopper replied on Wednesday, November 12, 2008

Did these issues get reported? If so, is there a response from Microsoft?

RockfordLhotka replied on Wednesday, November 12, 2008

Not by me – I haven’t had time to look at any of these issues I’m afraid…

 

Rocky

 

From: Atopper [mailto:cslanet@lhotka.net]
Sent: Wednesday, November 12, 2008 10:35 AM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] WPFToolkit DataGrid and EditableRootList Update 2nd time

 

Did these issues get reported? If so, is there a response from Microsoft?

vschuhma replied on Saturday, November 15, 2008

tried to find out where to report to. I couldn't find the appropriate forum for this. I had a look at Vincent Sibal's blog where a lot about data grid is explained but no success.

I have started to work with the new version just released. Although it looks like the bug is still there. Still investigating my code wether I have made some stupid mistake. Would be nice to hear if anyone else got the DataGrid working?

Regards Volker

Atopper replied on Sunday, November 16, 2008

I will start working with this in the next week, I'll report any issues here. I think issues can be reported at: http://www.codeplex.com/wpf/WorkItem/List.aspx.

Atopper replied on Saturday, November 22, 2008

Let me say first that this may be totally wrong. I got the DataGrid working by wrapping my BusinessListBase in an ObservableCollection. If anyone has a better solution, I'm all ears.

RockfordLhotka replied on Saturday, November 22, 2008

Wouldn’t it be a joke if all of WPF works with IBindingList except for the grid?

 

The one thing I’ve been trying to avoid is different versions of the collection base classes for WPF from every other part of .NET. But perhaps it is unavoidable – a compiler directive or something so you build a “WPF version” of CSLA for WPF, and an “everything else” version for everything else…

 

Rocky

 

 

From: Atopper [mailto:cslanet@lhotka.net]
Sent: Saturday, November 22, 2008 5:27 PM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] RE: WPFToolkit DataGrid and EditableRootList Update 2nd time

 

Let me say first that this may be totally wrong. I got the DataGrid working by wrapping my BusinessListBase in an ObservableCollection. If anyone has a better solution, I'm all ears.


Atopper replied on Monday, November 24, 2008

I found a bug in my code. I was not correctly assigning the new instance of my business class to the grid’s ItemsSource property when doing the save. I assumed that the grid would work by picking up the DataContext of the parent. I do not know if this is the intended/correct behavior of the DataGrid, but my code does seem to be correctly functioning without the use of the ObservableCollection. In addition, I do all of my data binding in code, rather than in XAML for this project so I do not know if using XAML would yeild the same results.

Copyright (c) Marimer LLC