WinformPocForm.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. namespace ListViewNativeArrowIconPoC
  11. {
  12. public partial class WinformPocForm : Form
  13. {
  14. private readonly ColumnSorter _lstColumnSorter = new ColumnSorter();
  15. public WinformPocForm()
  16. {
  17. InitializeComponent();
  18. MainListView.ListViewItemSorter = _lstColumnSorter;
  19. }
  20. private void MainListView_ColumnClick(object sender, ColumnClickEventArgs e)
  21. {
  22. var listView = (ListView)sender;
  23. // Determine if clicked column is already the column that is being sorted.
  24. if (e.Column == _lstColumnSorter.SortColumn)
  25. {
  26. // Reverse the current sort direction for this column.
  27. _lstColumnSorter.Order =
  28. _lstColumnSorter.Order == SortOrder.Ascending
  29. ? SortOrder.Descending
  30. : SortOrder.Ascending;
  31. }
  32. else
  33. {
  34. // Set the column number that is to be sorted; default to ascending.
  35. _lstColumnSorter.SortColumn = e.Column;
  36. _lstColumnSorter.Order = SortOrder.Ascending;
  37. }
  38. // Perform the sort with these new sort options.
  39. listView.Sort();
  40. listView.SetSortIcon(_lstColumnSorter.SortColumn, _lstColumnSorter.Order);
  41. }
  42. }
  43. }