diff --git a/v2rayN/v2rayN/Base/ListViewSort.cs b/v2rayN/v2rayN/Base/ListViewSort.cs new file mode 100644 index 00000000..fded9bed --- /dev/null +++ b/v2rayN/v2rayN/Base/ListViewSort.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace v2rayN.Base +{ + public class ListViewSort : IComparer + { + private int col; + private bool descK; + public ListViewSort() + { + col = 0; + } + public ListViewSort(int column, object Desc) + { + descK = (bool)Desc; + col = column; //当前列,0,1,2...,参数由ListView控件的ColumnClick事件传递 + } + public int Compare(object x, object y) + { + int tempInt = String.Compare(((ListViewItem)x).SubItems[col].Text, ((ListViewItem)y).SubItems[col].Text); + if (descK) return -tempInt; + else return tempInt; + } + } +} diff --git a/v2rayN/v2rayN/Forms/MainForm.cs b/v2rayN/v2rayN/Forms/MainForm.cs index c0d08b49..ef48980e 100644 --- a/v2rayN/v2rayN/Forms/MainForm.cs +++ b/v2rayN/v2rayN/Forms/MainForm.cs @@ -182,6 +182,9 @@ namespace v2rayN.Forms lvServers.Columns.Add(EServerColName.testResult.ToString(), UIRes.I18N("LvTestResults"), 70); if (statistics != null && statistics.Enable) + lvServers.HeaderStyle = ColumnHeaderStyle.Clickable; + this.lvServers.AllowColumnReorder = true; + { lvServers.Columns.Add(EServerColName.todayDown.ToString(), UIRes.I18N("LvTodayDownloadDataAmount"), 70); lvServers.Columns.Add(EServerColName.todayUp.ToString(), UIRes.I18N("LvTodayUploadDataAmount"), 70); @@ -1627,5 +1630,18 @@ namespace v2rayN.Forms { tsbOptionSetting_Click(toolSslRouting, null); } + + private void lvServers_ColumnClick(object sender, ColumnClickEventArgs e) + { + if (lvServers.Columns[e.Column].Tag == null) + lvServers.Columns[e.Column].Tag = true; + bool flag = (bool)lvServers.Columns[e.Column].Tag; + if (flag) + lvServers.Columns[e.Column].Tag = false; + else + lvServers.Columns[e.Column].Tag = true; + lvServers.ListViewItemSorter = new ListViewSort(e.Column, lvServers.Columns[e.Column].Tag); + lvServers.Sort();//对列表进行自定义排序 + } } } diff --git a/v2rayN/v2rayN/v2rayN.csproj b/v2rayN/v2rayN/v2rayN.csproj index 65075779..c0ebf9e1 100644 --- a/v2rayN/v2rayN/v2rayN.csproj +++ b/v2rayN/v2rayN/v2rayN.csproj @@ -97,6 +97,7 @@ + Form