using System; using System.Collections; using System.Windows.Forms; namespace JWH.CONTROL { public class ListViewItemComparer : IComparer { public int Column { get; set; } = 0; public System.Windows.Forms.SortOrder SortOrder { get; set; } = System.Windows.Forms.SortOrder.Ascending; public ListViewItemComparer() { } public ListViewItemComparer(int column, System.Windows.Forms.SortOrder order = System.Windows.Forms.SortOrder.Ascending) { this.Column = column; this.SortOrder = order; } public int Compare(object x, object y) { int rtnValue = -1; rtnValue = String.Compare(((ListViewItem)x).SubItems[this.Column].Text, ((ListViewItem)y).SubItems[this.Column].Text); if (this.SortOrder == System.Windows.Forms.SortOrder.Descending) rtnValue *= -1; return rtnValue; } } }