How to sort column of WPF Datagrid

Joined
Jan 2, 2014
Messages
13
Reaction score
0
Hi there, any way to sort columns of an wpf datagrid? I'm looking for an answer for several days. I dont wanna have it static, I wanna have it as it works with an datagird within an win-form, so that every user can choose the column he liks to have sort. thanks' lot
 
Joined
Jan 2, 2014
Messages
13
Reaction score
0
well, thats the answer

Code:
<DataGrid.Columns>  
<DataGridTextColumn Header="Phone" SortDirection="Ascending"
                            Binding="{Binding Phone}"/>
  </DataGrid.Columns>
 
Joined
Apr 16, 2014
Messages
1
Reaction score
0
How about this

//create a collection view for the datasoruce binded with grid
ICollectionView dataView = CollectionViewSource.GetDefaultView(myDataGrid.ItemsSource);
//clear the existing sort order
dataView.SortDescriptions.Clear();
//create a new sort order for the sorting that is done lastly
dataView.SortDescriptions.Add(new SortDescription(strPropertyName, paramDirection));
//refresh the view which in turn refresh the grid
dataView.Refresh();

If you got any other problem ,you can turn to the following pages, hopefully, which can be of use.
mikestedman.blogspot.com/2012/07/wpf-datagrid-custom-column-sorting.html
e-iceblue.com/Knowledgebase/Spire.XLS/Program-Guide/How-to-Insert-Rows-in-Excel-via-C-/VB.NET.html

regards
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top