views:

6

answers:

1

Hi, When I sort one of the columns (click the header column) in DataGrid, does the change on UI (the row order) reflected back to the data source ? I use List object as source.

A: 

No, the UI sort has no effect on the data.

There is another way to sort directly the data (actually, the representation of the data), but connecting it to the normal UI functionality (clicking on a header to sort) might be a bit more involved and also has several other downsides: wrap the collection in an ICollectionView (ListCollectionView for instance) and use SortDescriptions or custom sort predicates to sort the items; the ICollectionView will stand between the source collection and the UI and you can get the sorted items from it.

Also, you can sort the source collection directly as well (either manually or by using a sortable collection), but again, you need to connect the datagrid headers to the sorting code, which means something along the lines of intercepting the click events of the headers and drawing appropriate glyphs for sort hints etc.

Alex Paven