-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathListViewItemComparer.cs
60 lines (53 loc) · 1.74 KB
/
ListViewItemComparer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System.Collections;
using System.Windows.Forms;
namespace TestPlanViewer
{
/// <summary>
/// ListViewItemComparer object
/// </summary>
public class ListViewItemComparer : IComparer
{
/// <summary>
/// The column we are sorting on
/// </summary>
private int column;
/// <summary>
/// The sort order
/// </summary>
private SortOrder order;
/// <summary>
/// Initializes a new instance of the ListViewItemComparer class
/// </summary>
public ListViewItemComparer()
{
this.column = 0;
this.order = SortOrder.Ascending;
}
/// <summary>
/// Initializes a new instance of the ListViewItemComparer class
/// </summary>
/// <param name="column">The column to sort on</param>
/// <param name="order">What order to sort with</param>
public ListViewItemComparer(int column, SortOrder order)
{
this.column = column;
this.order = order;
}
/// <summary>
/// Compare two list view items
/// </summary>
/// <param name="x">The first item</param>
/// <param name="y">The second item</param>
/// <returns>The compare int value</returns>
public int Compare(object x, object y)
{
int returnVal = string.Compare(((ListViewItem)x).SubItems[this.column].Text, ((ListViewItem)y).SubItems[this.column].Text);
// Reverse order for decending
if (this.order == SortOrder.Descending)
{
returnVal *= -1;
}
return returnVal;
}
}
}