This is a migrated thread and some comments may be shown as answers.

Correct event for data change...

12 Answers 723 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Kenneth Jamieson
Top achievements
Rank 1
Kenneth Jamieson asked on 21 Oct 2009, 10:31 PM

Ok,

Getting closer to having the grid beaten into shape. Just two more things to solve. In this post, let's deal with detecting the change of an underlying data record.

The grid is clearly NOTICING the record data changes, as they are reflected in real time. If I change the data via my detail window, the grid column updates instantly and automatically. However, the grouping is not re-evaluated, so if the change would place the row in a different group it does not move.

I need to detect the data change, and then re-group the grid so that this change happens. However neither SourceUpdated() or DataContextChanged() fire – so I am clearly looking in the wrong places :)

Any hints?

 

Ken

12 Answers, 1 is accepted

Sort by
0
Stefan Dobrev
Telerik team
answered on 22 Oct 2009, 12:49 PM
Hi Kenneth,

The grid will automatically refresh itself if you change the grouped values via editing in the grid's cell. If you edit the data externally you should call the Rebind() method of the grid which will refresh the grid.

Best wishes,
Stefan Dobrev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Kenneth Jamieson
Top achievements
Rank 1
answered on 22 Oct 2009, 12:57 PM
Maybe I wasn't clear.

I use the grid to show records, grouped by a "Parent" column. When a row is selected and the user wants to edit the data, a new Wpf detail window is popped up to to show the form. Now, when they change somethign in that form, in that other window - the grid notices the change instantly, without any code from me due to the nature of the underlying datacollection mechanisms.

So far, so good.

However, if the "parent" data changes, even though the parent column in the grid shows the new content, the GROUPING never re-runs - so the row remains grouped in the wrong place.

Firing a cross window event is silly, since the underlying data mechanism of Wpf handles the situation just fine. it is only due to a bug in the grid itself with respect to grouping that there is an issue.

Since the grid DOES NOTICE the data change (it must, it changes the content it just doesnt re-group) I assume there is an event I can hook that says "hey! something changed!" so I can call rebind() to try and work around the bug. However, the events I mentioned are the ones that SHOULD be firing, but they simply don't.

Is that any clearer? I am really hoping there is a better answer than force it by hand, without even the benefit of events to help.

Ken


0
Stefan Dobrev
Telerik team
answered on 22 Oct 2009, 01:24 PM
Hello Kenneth,

I understand you scenario clearly. The point is that the cell's of the grid are updated via the binding that is set on the column. The grid actually did not understand that some property of a given object is changed, everything is done via the magic of bindings.

If you want to have a clear way to achieve this is to pass an IEditableCollectionView as a source to the grid. This way you can call BeginEdit() method of the the view when you start to edit an item in your detail window. When the editing is finished you should call CommitEdit() either use ListCollectionView or our own implementation QueryableCollectionView as your ItemsSource. They both implement IEditableCollectionView.

Regards,
Stefan Dobrev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Kenneth Jamieson
Top achievements
Rank 1
answered on 22 Oct 2009, 06:11 PM
On some level, your grid MUST know something changed - it has to display the changes right? Or are you wraping the MS grid "under the covers" and thus not realy fully aware of what is happening under there?

Of course, the real answer is for the bug int he grid (and it is a bug in the grid) to be fixed so that grouping works properly.

0
Vlad
Telerik team
answered on 23 Oct 2009, 06:16 AM
Hello,

I'm not sure what do you mean with: "are you wraping the MS grid "under the covers" and thus not realy fully aware of what is happening under there" - can you explain?

Basically the grid will react immediately on two very popular events - INotifyCollectionChanged and INotifyPropertyChanged. If you do not have these nothing will be changed!

Can you post a scenario with any other grid where our grid does no work correctly?

All the best,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Kenneth Jamieson
Top achievements
Rank 1
answered on 23 Oct 2009, 08:12 AM

 

You guys DO notice the data change. You just don’t completely update i response. :)

See the attached screenshot for a maybe more useful description of the problem. And since (in this case) the grid ALSO doesnt file any changed events, I can't do a rebind by hand via the grid.

0
Vlad
Telerik team
answered on 23 Oct 2009, 09:31 AM
Hi,

I've made for you small example application to illustrate you how to achieve you goal. You can find the project attached.

Regards,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Kenneth Jamieson
Top achievements
Rank 1
answered on 23 Oct 2009, 01:05 PM

Thanks for taking the time – and I see what you did… but I don’t see why it is necessary. The data collection I am using is a Astoria ADO.NET Data Services generated one. I don’t need to hand wrangle it even a little to work as a data provider for every other binding purpose.

My real question is – is this a bug, or did you guys deliberately decide not to refresh the groupings even when you clearly see that a grouped value has changed?

0
Kenneth Jamieson
Top achievements
Rank 1
answered on 23 Oct 2009, 01:07 PM

Hey Stefan!

Do you know why this is needed? The Grid DOES see the changed values, it simply doesn’t updating the grouping. It updated every other thing that depends on the data but that.

Bug? Feature?

Thanks!

0
Vlad
Telerik team
answered on 23 Oct 2009, 01:23 PM
Hello Kenneth,

Actually the grid does not see this change - only the cell Binding can see it. The main idea behind not supporting by default such scenario is less memory consumption and better performance.

Lets assume that the grid will check every object in your collection if implements INotifyPropertyChanged, subscribe to PropertyChanged event for every item and check if the grid is grouped by this property when the event is raised and finally raise CollectionChanged to refresh the rows and groups. If you have large collection of objects with such approach you will get lots of event handlers (even memory leaks most probably if you do not clean all these), more memory consumption and less responsive grid/application.

Microsoft for example will not support such scenario by default in their WPF toolkit grid exactly because of such possible problems.

Sincerely yours,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Kenneth Jamieson
Top achievements
Rank 1
answered on 23 Oct 2009, 01:31 PM

Now thats the info I needed :)

Now of couse, it stll has to be done - by the grid or by me to get your grouping functionality to work as expected. It is still very surprising that an object so dynamic simply falls down on something like this. You could subscribe to the event only from the cells that are being grouped on, for instance.
0
Kenneth Jamieson
Top achievements
Rank 1
answered on 27 Oct 2009, 11:06 AM
In the end I had to manually add an event to my edit wndo and subscribe to it, then rebind the grid  Sily, but the only way to get it working.

Case closed! Thanks for all yor help!
Tags
GridView
Asked by
Kenneth Jamieson
Top achievements
Rank 1
Answers by
Stefan Dobrev
Telerik team
Kenneth Jamieson
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or