forked from daggen/XrmToolBox-Plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ListViewItemComparer.cs
83 lines (71 loc) · 2.14 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using System;
using System.Collections;
using System.Windows.Forms;
namespace Daggen.SecurityRole
{
/// <summary>
/// Compares two listview items for sorting
/// </summary>
internal class ListViewItemComparer : IComparer
{
#region Variables
/// <summary>
/// Index of sorting column
/// </summary>
private readonly int col;
/// <summary>
/// Sort order
/// </summary>
private readonly SortOrder innerOrder;
#endregion Variables
#region Constructors
/// <summary>
/// Initializes a new instance of class ListViewItemComparer
/// </summary>
public ListViewItemComparer()
{
col = 0;
innerOrder = SortOrder.Ascending;
}
/// <summary>
/// Initializes a new instance of class ListViewItemComparer
/// </summary>
/// <param name="column">Index of sorting column</param>
/// <param name="order">Sort order</param>
public ListViewItemComparer(int column, SortOrder order)
{
col = column;
innerOrder = order;
}
#endregion Constructors
#region Methods
/// <summary>
/// Compare tow objects
/// </summary>
/// <param name="x">object 1</param>
/// <param name="y">object 2</param>
/// <returns></returns>
public int Compare(object x, object y)
{
return Compare((ListViewItem)x, (ListViewItem)y);
}
/// <summary>
/// Compare tow listview items
/// </summary>
/// <param name="x">Listview item 1</param>
/// <param name="y">Listview item 2</param>
/// <returns></returns>
public int Compare(ListViewItem x, ListViewItem y)
{
if (innerOrder == SortOrder.Ascending)
{
return String.Compare(x.SubItems[col].Text, y.SubItems[col].Text);
}
else
{
return String.Compare(y.SubItems[col].Text, x.SubItems[col].Text);
}
}
#endregion Methods
}
}