2

I have a RadGridView control on my form bound to a collection in my ViewModel. When I add a new item to my collection, it does show the item in the grid, but it's always placed at the end and not respecting the current sort. Does anybody know how to fix this?

Thanks!

Mike Cole
  • 14,474
  • 28
  • 114
  • 194

2 Answers2

1

Not sure what issue you are running into, but I threw together a quick proof of concept and everything seemed to work as expected. Check out the download available here:

Quick grid demo

and let me know how it differs from your setup. I sorted by ID, then when adding new items the new items populate into the sorted collection as expected since they are made with a random ID that falls inside of the original range. Perhaps you aren't using an ObservableCollection or *CollectionView?

-Evan

Evan Hutnick
  • 534
  • 3
  • 5
  • I'm using the EntityCollection that EF generated... I'm binding the grid directly to the model. – Mike Cole May 18 '11 at 21:56
  • AHhh, when I converted to an ObservableCollection then the grid worked as expected when adding a new item. However, it did not respect the sort when editing an item. – Mike Cole May 19 '11 at 20:59
  • Ahh, true true, in that case try wrapping your EF model into a QueryableCollectionView (add System.Windows.Data to your references). QCV initializes with an IEnumerable collection, can be bound to your view via the same binding, and sends update notifications when editing or anything else so that RadGridView can respect that. Let me know if you need a demo worked up. :) – Evan Hutnick May 19 '11 at 21:58
  • I tried the QueryableCollectionView, but I seem to have lost the sortability again on add, and edit still does work. – Mike Cole May 20 '11 at 02:30
0

If using a ObservableCollection solves your problem when a new item is added you could use the CellEditEnded event to reset the sorting on the grid.

You can subscribe to the event in code or the xaml; take a look at CellEditEnded documentation. In the handler you could then unset the sorting and then set it again.

I have not tried this with the telerik components only with a WPF DataGrid.

Viktor Seifert
  • 636
  • 1
  • 7
  • 17