Click here to Skip to main content
15,894,720 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to sort DataGrid programatically in WPF application when ItemSource of same is available?

I tried like,

C#
var dataView = CollectionViewSource.GetDefaultView(mygridobject.ItemSource);
            dataView.SortDescriptions.Clear();
            dataView.SortDescriptions.Add(new SortDescription("Column Name", ListSortDirection.Ascending));
            dataView.Refresh();


But, I got an exception saying, this is not supported. If any one knows about it, please guide me how to proceed?
Posted
Updated 26-Aug-15 9:36am
v2
Comments
Maciej Los 26-Aug-15 15:37pm    
Full exception message, please.
Pradeep Kumar G M 27-Aug-15 3:20am    
Specified method is not supported.
Maciej Los 27-Aug-15 3:21am    
And details...
VR Karthikeyan 14-Sep-15 2:31am    
Your code is working perfectly for me.

var dataView = CollectionViewSource.GetDefaultView(mygridobject.ItemsSource); //ItemsSource misspelled as ItemSource
dataView.SortDescriptions.Clear();
dataView.SortDescriptions.Add(new SortDescription("Column Name", ListSortDirection.Descending));
dataView.Refresh();

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900