OSDN Git Service

initial build for opensource
[applistation/AppliStation.git] / AppliStation / AppliStation.Util / ListViewItemSortComparer.cs
1 using System;\r
2 using System.Drawing;\r
3 using System.Windows.Forms;\r
4 using NaGet.Packages;\r
5 using NaGet.Packages.Install;\r
6 using System.IO;\r
7 using System.Collections.Generic;\r
8 \r
9 namespace AppliStation.Util\r
10 {\r
11         class ListViewItemSortComparer : System.Collections.IComparer\r
12         {\r
13                 public SortOrder Order = SortOrder.Ascending;\r
14                 \r
15                 public int Column = -1;\r
16                 \r
17                 public ListViewItemSortComparer(int index, SortOrder order)\r
18                 {\r
19                         this.Column = index;\r
20                         this.Order = order;\r
21                 }\r
22                 \r
23                 public int Compare(object x, object y)\r
24                 {\r
25                         ListViewItem itemx = (ListViewItem) x;\r
26                         ListViewItem itemy = (ListViewItem) y;\r
27                         \r
28                         int result = -1;\r
29                         result = string.Compare(itemx.SubItems[Column].Text,\r
30                                                 itemy.SubItems[Column].Text);\r
31                         \r
32                         switch (Order) {\r
33                                 case SortOrder.Descending:\r
34                                         result =  -result;\r
35                                         break;\r
36                                 case SortOrder.None:\r
37                                         result = 0;\r
38                                         break;\r
39                         }\r
40                         return result;\r
41                 }\r
42         }\r
43 }\r