Articles in this section

How to sort data in WinForms Spreadsheet?

Sorting

WinForms Spreadsheet (SfSpreadsheet) provides support to sort a range of cells in the workbook based on data. Sorting can be done based on cell values, font color and cell color respectively. For more information, please go through XlsIO UG link. 

For sorting process,

  • Create a data sorter of workbook in SfSpreadsheet.
  • Set a sorting range to sort the data in the IRange of the worksheet.
  • Set the sort order and type of sort to be performed in the selected range by using ISortField interface.
  • Then the sorting operation can be done by invoking the Sort method of IDataSort interface.
  • Finally invalidate the cells to refresh the view in SpreadsheetGrid.


The following code illustrates how to perform the sorting operation in Spreadsheet.

IDataSort sorter = this.spreadsheet.Workbook.CreateDataSorter();
 
//To sort a range of cells,
sorter.SortRange = this.spreadsheet.ActiveSheet.Range["E3:E8"];
sorter.HasHeader = false;
ISortField sortField = sorter.SortFields.Add(4, SortOn.Values,OrderBy.Ascending);
sorter.Sort();
sorter.SortFields.Remove(sortField);
spreadsheet.ActiveGrid.InvalidateCell(GridRangeInfo.Cells(2,5,8,6), true);
 
// To sort a particular column
sorter.SortRange = this.spreadsheet.ActiveSheet. Range["C3:C12"];
sorter.HasHeader = false;
ISortField sortField = sorter.SortFields.Add(2, SortOn.Values,OrderBy.Descending);
sorter.Sort();
sorter.SortFields.Remove(sortField);
spreadsheet.ActiveGrid.InvalidateCell(GridRangeInfo.Col(2), true);
Samples:

WPF

WinRT

WinForms

UWP

 

Conclusion


I hope you enjoyed learning about how to sort the data in a Spreadsheet.


You can refer to our WinForms Spreadsheet feature tour page to know about its other groundbreaking feature representations, WinForms Spreadsheet documentation, and how to quickly get started for configuration specifications. You can also explore our  WinForms Spreadsheet example to understand how to create and manipulate data.


For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.


If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you! 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied