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

How to instantiate a DataItemCollection?

1 Answer 211 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Roger
Top achievements
Rank 1
Roger asked on 17 Aug 2011, 07:42 PM
On this page, there is a note that states "If you use DataItemCollection as data source, the RadGridView will automatically synchronize the SortDescriptors of the source with its own ones." There is nothing describing how to instantiate a DataItemCollection, the constructor is internal, and there are very few examples of DataItemCollection ever being used, but it seems like it would help with my current scenario.

The reason for my wanting to use DataItemCollection came from a problem that I saw with maintaining selectability in the RadGridView. I have a class derived from ObservableCollection containing a property of type ListCollectionView, with SortDescriptions defined. The collection view is applied to the grid's ItemsSource. This is my problem scenario:
  1. I manually add a row to the grid view, through a button, by calling ListCollectionView.Add().
  2. I fill out the data in the cells and press enter.
  3. The CommitEdit() handling executes.
  4. Sorting is executed on the collection view.
    • On the ListCollectionView.CurrentChanging event, the collection view has its CurrentItem set to the edited row item.
    • On the ListCollectionView.CurrentChanged event, the collection view has its CurrentItem set to null!

I had tried creating a custom KeyboardCommandProvider, where I set only the CommitEdit and SelectCurrentItem commands, but that didn't make a difference (the commit still causes the unwanted chain of events).

This all works as intended if I remove the SortDescriptions from the collection view but I need them. How can I resolve this? Would using a DataItemCollection instead of a ListCollectionView help me in any way?

I am using Q1 of the WPF controls (version 2011.1.419.40).

1 Answer, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 22 Aug 2011, 10:53 AM
Hi Roger,

 Indeed you are right that the help article is not accurate at this point. There should be ICollectionView(as the RadGridView will automatically synchronize the SortDescriptors of the ICollectionView source with its own ones). We are going to update this sentence.

In this forum thread I am going to summarize what my colleague has replied to you in your other post. In the case you describe, you can try binding RadGridView.ItemsSource to an instance of our QueryableCollectionView class. Since it implements the ICollectionView interface, it has a SortDescriptions property.

The QueryableCollectionView class is created by passing in the raw source collection in its constructor. If you want to sort this QueryableCollectionView you can add a SortDescriptor to its SortDescriptors collection. Still the better approach will be to sort RadGridView directly through its SortDescriptors collection.

All the best,
Didie
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
GridView
Asked by
Roger
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Share this question
or