Here I will post problems I and my colleagues met and solutions we found.

Wednesday, December 24, 2008

Sorting in WPF DataGrid

As you could see from my previous post, I am using WPF Toolkit DataGrid now. One of the reason to do it is to sort data. Sure, it is possible to do sorting in ListView, but using DataGrid I can do it with less efforts.

The only problem was that what I had as data source was regular BindingList, that does not support sorting. So, sorting just didn't work.

The solution I found the easiest is using Linq. Since I assigned my data source in code, not XAML, there was no inconvenience at all.

Instead of line


ItemsSource = list


I used


ItemsSource = from item in list select item;

1 comment:

BLIZZER said...

hey but when i am using the same as u did...its sorting frequently and goes back to its original state.

did you did something in u r xaml file..

please can you more explore about it or post the complete code