1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
5
using System.Collections.Generic;
6
using System.Windows.Forms;
8
namespace ICSharpCode.SharpDevelop.Widgets.ListViewSorting
11
/// Compares ListViewItems by comparing multiple columns,
12
/// using an object that implements <see cref="IListViewItemComparer"/>
13
/// for every column to compare.
15
public class ListViewMultipleColumnsComparer : IListViewItemComparer
17
readonly List<IListViewItemComparer> comparers = new List<IListViewItemComparer>(2);
18
readonly List<int> columns = new List<int>(2);
21
/// Initializes a new instance of the <see cref="ListViewMultipleColumnsComparer"/> class.
23
/// <param name="firstComparer">The <see cref="IListViewItemComparer"/> to use to compare the first column.</param>
24
/// <param name="firstColumn">The 0-based index of the first column to compare.</param>
25
/// <param name="secondComparer">The <see cref="IListViewItemComparer"/> to use to compare the second column.</param>
26
/// <param name="secondColumn">The 0-based index of the second column to compare.</param>
28
/// You can add more columns to compare by using the <see cref="AddComparer"/> method.
30
public ListViewMultipleColumnsComparer(IListViewItemComparer firstComparer, int firstColumn, IListViewItemComparer secondComparer, int secondColumn)
32
if (firstComparer == null) {
33
throw new ArgumentNullException("firstComparer");
35
if (secondComparer == null) {
36
throw new ArgumentNullException("secondComparer");
39
this.AddComparer(firstComparer, firstColumn);
40
this.AddComparer(secondComparer, secondColumn);
44
/// Adds another column to compare.
46
/// <param name="comparer">The <see cref="IListViewItemComparer"/> to use to compare this column.</param>
47
/// <param name="column">The 0-based index of the column to compare.</param>
48
public void AddComparer(IListViewItemComparer comparer, int column)
50
if (comparer == null) {
51
throw new ArgumentNullException("comparer");
53
this.comparers.Add(comparer);
54
this.columns.Add(column);
57
public int Compare(ListViewItem lhs, ListViewItem rhs, int column)
61
for (int i = 0; i < this.comparers.Count; i++) {
62
if ((compareResult = this.comparers[i].Compare(lhs, rhs, this.columns[i])) != 0) {