public int Compare(object x, object y) { int result = 0; int sortColumn = fOwner.fSortColumn; MVPSortOrder sortOrder = fOwner.fSortOrder; if (sortOrder != MVPSortOrder.None && sortColumn >= 0) { ListViewItem item1 = (ListViewItem)x; ListViewItem item2 = (ListViewItem)y; if (sortColumn == 0) { if (item1 is IComparable && item2 is IComparable) { IComparable eitem1 = (IComparable)x; IComparable eitem2 = (IComparable)y; result = eitem1.CompareTo(eitem2); } else { result = GKListView.StrCompareEx(item1.Text, item2.Text); } } else if (sortColumn < item1.SubItems.Count && sortColumn < item2.SubItems.Count) { ListViewItem.ListViewSubItem subitem1 = item1.SubItems[sortColumn]; ListViewItem.ListViewSubItem subitem2 = item2.SubItems[sortColumn]; if (subitem1 is IComparable && subitem2 is IComparable) { IComparable sub1 = (IComparable)subitem1; IComparable sub2 = (IComparable)subitem2; result = sub1.CompareTo(sub2); } else { result = GKListView.StrCompareEx(subitem1.Text, subitem2.Text); } } if (sortOrder == MVPSortOrder.Descending) { result = -result; } } return(result); }
public int CompareTo(object obj) { GKListSubItem otherItem = obj as GKListSubItem; if (otherItem == null) { return(-1); } if (fValue is string && otherItem.fValue is string) { return(GKListView.StrCompareEx((string)fValue, (string)otherItem.fValue)); } IComparable cv1 = fValue as IComparable; IComparable cv2 = otherItem.fValue as IComparable; int compRes; if (cv1 != null && cv2 != null) { compRes = cv1.CompareTo(cv2); } else if (cv1 != null) { compRes = -1; } else if (cv2 != null) { compRes = 1; } else { compRes = 0; } return(compRes); }