OSDN Git Service

AppliStation,バージョンを1.1.0.*に変更。ソースファイルへのコメントの加筆
[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         /// <summary>\r
12         /// ListView\82Ì\83\\81[\83g\82ð\83J\83v\83Z\83\8b\89»\82·\82é\82½\82ß\82Ì\83N\83\89\83X\r
13         /// </summary>\r
14         class ListViewItemSortComparer : System.Collections.IComparer\r
15         {\r
16                 /// <summary>\r
17                 /// \83\\81[\83g\82Ì\95û\8cü\81B\8f¸\8f\87\82©?\8d~\8f\87\82©?\r
18                 /// </summary>\r
19                 public SortOrder Order = SortOrder.Ascending;\r
20                 \r
21                 /// <summary>\r
22                 /// \83\\81[\83g\91Î\8fÛ\82Ì\83R\83\89\83\80\83C\83\93\83f\83b\83N\83X\r
23                 /// </summary>\r
24                 public int Column = -1;\r
25                 \r
26                 /// <summary>\r
27                 /// \83R\83\93\83X\83g\83\89\83N\83^\r
28                 /// </summary>\r
29                 /// <param name="index">\83\\81[\83g\91Î\8fÛ\82Ì\83R\83\89\83\80\83C\83\93\83f\83b\83N\83X</param>\r
30                 /// <param name="order">\83\\81[\83g\82Ì\95û\8cü\81B\8f¸\8f\87\82©?\8d~\8f\87\82©?</param>\r
31                 public ListViewItemSortComparer(int index, SortOrder order)\r
32                 {\r
33                         this.Column = index;\r
34                         this.Order = order;\r
35                 }\r
36                 \r
37                 public int Compare(object x, object y)\r
38                 {\r
39                         ListViewItem itemx = (ListViewItem) x;\r
40                         ListViewItem itemy = (ListViewItem) y;\r
41                         \r
42                         int result = -1;\r
43                         result = string.Compare(itemx.SubItems[Column].Text,\r
44                                                 itemy.SubItems[Column].Text);\r
45                         \r
46                         switch (Order) {\r
47                                 case SortOrder.Descending:\r
48                                         result =  -result;\r
49                                         break;\r
50                                 case SortOrder.None:\r
51                                         result = 0;\r
52                                         break;\r
53                         }\r
54                         return result;\r
55                 }\r
56         }\r
57 }\r