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

RadGridView shows incorrect data from ObservableCollection

9 Answers 242 Views
GridView
This is a migrated thread and some comments may be shown as answers.
denis curtis
Top achievements
Rank 1
denis curtis asked on 21 Mar 2010, 05:24 AM

I have a RadGridView bound to ObservableCollection. This collection is constantly updated and on first binding the grid represent the data correctly. But then I click on one of the headers to sort the data in the grid. After that behaviors on adding a new row become as following:
-  the grid adds the row to the end of the list only, it doesn't sort data dynamically according sorting column;
- sometimes (often) the grid creates duplicate rows while underlying collection contains correct data;

I couldn't find in documentation any info that I should programmatically sort underlying collection each time after adding row or rebind it every time so the grid shows it correctly. What should I do to fix it or it\s a norm for Telerik Grid?

9 Answers, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 22 Mar 2010, 11:16 AM
Hello denis curtis,

RadGridView should work as expected in such scenarios. I have tried to reproduce the issue with a test application but everything worked just fine. Maybe the application doesn't exactly match your scenario. Could you please take a look at the attached application and try to reproduce the problem?

Thank you for your time.


Best wishes,
Milan
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
denis curtis
Top achievements
Rank 1
answered on 23 Mar 2010, 12:58 AM

Milan. thank you for your reply. Your sample works and for every field! Not for “Number” only! Well… I modified your sample to make it easier from one side and injected some logic to make it close to real life. I removed Club class as we need the sample clearly but it’s just cosmetic changes. Then I implemented logic that adds, removes and updates items in the collection on each “button click”. In result what we have? The Grid is able to sort the data by Integer (ie “Number”) field only!!! It doesn’t sort by any other field automatically!

What’s wrong?
ps/ the project solution i'll try to send via ticket

Thank you! denis

0
Milan
Telerik team
answered on 23 Mar 2010, 12:59 PM
Hi denis curtis,

Thank you for sending a sample project. I noticed that you change some properties in the performPlayers() method. Unfortunately if you change a property using code and grid is sorting by that property the data will not be reordered to reflect the new property change. The ObservableCollection can help in situation where items are added/removed/moved/replaced but not in situation where item properties are changed. 

To handle such situation you can call the Rebind method of RadGridView right after data items are changed:

private void Button_Click(object sender, RoutedEventArgs e) 
    players.performPlayers(); 
    this.playersGrid.Rebind(); 
}


Best wishes,
Milan
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
denis curtis
Top achievements
Rank 1
answered on 23 Mar 2010, 04:30 PM
"Rebind" is the most "expensive" operation ont the Grid. If you need to rebind grid after each property change, which happen 10 times per sec or more, the apllication will be working on this only.... 
the strange thing is that changing "integer" typed property is not required to rebind grid and it sort tows as requred. Any proper solutions?
Thank you
 denis
0
Vlad
Telerik team
answered on 23 Mar 2010, 05:17 PM
Hi denis,

The grid will not be refreshed automatically no matter if the property is integer or not - you can use however our ObservableItemCollection and call Reset when needed to achieve your goal.

I've attached an example project demonstrating RadGridView sorted descending on integer property and refreshed every millisecond.

Best wishes,
Vlad
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
denis curtis
Top achievements
Rank 1
answered on 23 Mar 2010, 06:14 PM

Indeed, in my example the grid sorts the data automatically if Number (“integer type”) column selected for sorting! It doesn’t require rebind! But you said it does’t….

 

I can’t use your ObservableItemCollection because I already use my “special” ObservableCollection which can dispatch events to UI from multi-threads environment informing grid on propertyChanging. RadGrid should handle this and it handles in simple situations like on adding items only…. but it doesn’t support as I can see the basic functionality that any grid should support ie sort items according required columns upon item changed is sortProperty is set…

Now I should think how to propagate CollectionChanged event from the thread to RadGrid so it could re-bind or somehow resort the content…

Thank you

denis

0
denis curtis
Top achievements
Rank 1
answered on 24 Mar 2010, 03:30 PM

Upgraded wpf from 09q3 to 10q1 (vs2008) and tested today.

Currently in the application I use the one instance of the grid which rebinding to different sources therefore AutoGenerateColumns="True" and no any column definitions and soft definitions.

In the previous version (09q3) when I selected a column for sort and then changed the source the application crashed if it couldn’t find the same sort column in new source. Now as I can see it was fixed and app continue running.

The most interesting thing is that now all columns are sorted automatically, even when property updated (not only ne items added). At least it sorts string and int and decimal columns (properties).

Well.. the question is if Telerik developer is not sure of the grid behaviors how I can sure that in the next release all these behaviors stays the same?

Thank you for your help!

denis

0
Vlad
Telerik team
answered on 24 Mar 2010, 03:39 PM
Hi,

The application attached to this thread is using actually our Q1 2010 binaries.

All the best,
Vlad
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Carolina
Top achievements
Rank 1
answered on 14 Jun 2013, 07:43 PM
Hello Milan,

You said that if I change a property using code and grid is sorting by that property the data will not be reordered to reflect the new property change.

Is it still necessary to rebind the grid when the property is changed?

Thanks!
Tags
GridView
Asked by
denis curtis
Top achievements
Rank 1
Answers by
Milan
Telerik team
denis curtis
Top achievements
Rank 1
Vlad
Telerik team
Carolina
Top achievements
Rank 1
Share this question
or