internal RowSorterHelper GetRowSorterHelper()
 {
     for (int i = 0; i < rowSorterList.Count; i++)
     {
         RowSorterHelper rs = (RowSorterHelper)rowSorterList[i];
         if (rs != null && rs.ColumnIndex == LastSortedColumn)
         {
             return(rs);
         }
     }
     return(null);
 }
        public int Compare(object obj1, object obj2)
        {
            ListViewItem    item1   = (ListViewItem)obj1;
            ListViewItem    item2   = (ListViewItem)obj2;
            RowSorterHelper rs      = listView.GetRowSorterHelper();
            string          string1 = item1.Text;
            string          string2 = item2.Text;
            int             result  = 0;

            if (listView.LastSortedColumn != 0)
            {
                // adjust the objets if we have to sort subitems
                string1 = item1.SubItems[listView.LastSortedColumn].Text;
                string2 = item2.SubItems[listView.LastSortedColumn].Text;
                Debug.Assert(obj1 != null && obj2 != null);
            }

            if (rs != null)
            {
                if (rs.Format == SortedListViewFormatType.String)
                {
                    result = CompareStrings(string1, string2, listView.Sorting);
                }
                else if (rs.Format == SortedListViewFormatType.Numeric)
                {
                    result = CompareNumbers(string1, string2, listView.Sorting);
                }
                else if (rs.Format == SortedListViewFormatType.Date)
                {
                    result = CompareDates(string1, string2, listView.Sorting);
                }
                else if (rs.Format == SortedListViewFormatType.Custom)
                {
                    if (rs.SortEvent != null)
                    {
                        result = rs.SortEvent((ListViewItem)obj1, (ListViewItem)obj2);
                        if (listView.Sorting == SortOrder.Descending)
                        {
                            result *= -1;
                        }
                    }
                }
            }
            else if (rs == null)
            {
                // Consider column as strings
                result = CompareStrings(string1, string2, listView.Sorting);
            }

            return(result);
        }