I have a grid with multiple columns and users can sort based on any column. Data, which is bound the grid is a collection of custom entity. I have a print button on the screen and on click of this button I need to do a custom print. Print must show the data in the same order as displayed in the grid (with additional data)
Is there any way to directly get the sorted datasource instead of sorting the datasource in the sorting event?
Thanks Pankaj
To sort items in a DataGridCreate a SortDescription that specifies the property to sort by. You can specify the property in XAML or in code. In XAML, set the PropertyName to the name of the property to sort by. In code, pass the name of the property to sort by and the ListSortDirection to the constructor.
WPF DataGrid (SfDataGrid) allows you to sort the data against one or more columns either in ascending or descending order. The sorting can be performed by clicking a column header. You can enable/disable the sorting for all the columns in DataGrid by using DataGrid. AllowSorting property.
You have to use the yourDataGrid.Items, Items reflect the currentview of the grid. and you have to convert using the method Cast and after use .ToList();
imagine this
List<MyClass> myListOfMyClass = new List<MyClass>();
myGrid.ItemSource = myListOfMyClass;
List<MyClass> myListOfMyClassSortedByTheUser = myGrid.Items.Cast<MyClass>().ToList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With