Пример #1
0
        /// <summary>
        /// Sorts the ListView by the specified column.
        /// </summary>
        /// <param name="column"></param>
        public void Sort(int column)
        {
            // Toggle ASC and DESC
            if (column == lastsortcolumn)
            {
                if (sortorder == VelerSoftware.SZC.ListViewStored.Collections.SortOrder.Ascending)
                {
                    sortorder = VelerSoftware.SZC.ListViewStored.Collections.SortOrder.Descending;
                }
                else
                {
                    sortorder = VelerSoftware.SZC.ListViewStored.Collections.SortOrder.Ascending;
                }
            }
            else
            {
                sortorder = VelerSoftware.SZC.ListViewStored.Collections.SortOrder.Ascending;
            }

            lastsortcolumn = column;

            // Get the columns comparer (if the column ist registered use the StringComparer by default)
            ISortComparer c = null;

            if (comparercollection.ContainsKey(this.ListView.Columns[column].Text))
            {
                c = comparercollection[this.ListView.Columns[column].Text];
            }
            else
            {
                c = new VelerSoftware.SZC.ListViewStored.Collections.NameComparer();
            }

            // Initialize the ListViewItemComparer
            ListViewItemComparer lvc = new ListViewItemComparer(column, c);

            lvc.SortOrder = sortorder;
            this.ListView.ListViewItemSorter = lvc;

            // Sort!
            this.ListView.Sort();

            // Set ColumnHeaders image
            SetImage(column, sortorder);
        }
Пример #2
0
        /// <summary>
        /// Compare!
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public override int Compare(object x, object y)
        {
            string x1 = ((ListViewItem)x).SubItems[col].Text;
            string y1 = ((ListViewItem)y).SubItems[col].Text;

            if (comparer == null)
            {
                // Default is the StringComparer
                ISortComparer c = new VelerSoftware.SZC.ListViewStored.Collections.NameComparer();
                c.SortOrder = sortorder;
                return(c.Compare(x1, y1));
            }
            else
            {
                comparer.SortOrder = sortorder;
                return(comparer.Compare(x1, y1));
            }
        }