-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathClassListViewItemComparer.cs
More file actions
59 lines (48 loc) · 1.31 KB
/
ClassListViewItemComparer.cs
File metadata and controls
59 lines (48 loc) · 1.31 KB
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
/*
* Created by SharpDevelop.
* User: User
* Date: 20/05/2012
* Time: 23:02
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections;
using System.Windows.Forms;
namespace WordListAnalyser2
{
/// <summary>
/// Description of ListViewItemComparer.
/// </summary>
public class ListViewItemComparer : IComparer
{
public int Column {get; set;}
public bool Numeric {get; set;}
public ListViewItemComparer (int columnindex)
{
Column = columnindex;
}
public int Compare(object x, object y){
ListViewItem itemX = x as ListViewItem;
ListViewItem itemY = y as ListViewItem;
if (itemX == null && itemY == null)return 0;
else if(itemX == null)return -1;
else if(itemY == null)return 1;
if (itemX == itemY)return 0;
if (Numeric){
decimal itemXVal, itemYVal;
if (!Decimal.TryParse(itemX.SubItems[Column].Text, out itemXVal)){
itemXVal = 0;
}
if (!Decimal.TryParse(itemY.SubItems[Column].Text, out itemYVal)){
itemYVal = 0;
}
return Decimal.Compare(itemXVal,itemYVal);
}else {
string itemXText = itemX.SubItems[Column].Text;
string itemYText = itemY.SubItems[Column].Text;
return string.Compare(itemXText, itemYText);
}
}
}
}