ListViewColumnSorter.cs 901 B

123456789101112131415161718192021222324252627282930313233343536
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Collections;
  6. namespace PicSo
  7. {
  8. public class ListViewColumnSorter:IComparer
  9. {
  10. public int ColumnIndex { get; set; }
  11. bool isAsc = true;
  12. public ListViewColumnSorter()
  13. {
  14. this.ColumnIndex = 0;
  15. }
  16. public ListViewColumnSorter(int columnIndex,bool Asc)
  17. {
  18. this.ColumnIndex = columnIndex;
  19. this.isAsc = Asc;
  20. }
  21. public int Compare(object x, object y)
  22. {
  23. var k = (x as System.Windows.Forms.ListViewItem).SubItems[ColumnIndex].Text.CompareTo((y as System.Windows.Forms.ListViewItem).SubItems[ColumnIndex].Text);
  24. if (isAsc)
  25. {
  26. return k;
  27. }
  28. else
  29. {
  30. return -k;
  31. }
  32. }
  33. }
  34. }