首先是实现ListView控件的自定义排序,订阅ListView控件的ColumnClick事件
\n
private void listView1_ColumnClick(object sender, ColumnClickEventArgs e)
{
if (this.listView1.Columns[e.Column].Tag == null)
this.listView1.Columns[e.Column].Tag = true;
bool tabK = (bool)this.listView1.Columns[e.Column].Tag;
if (tabK)
this.listView1.Columns[e.Column].Tag = false;
else
this.listView1.Columns[e.Column].Tag = true;
this.listView1.ListViewItemSorter = new ListViewSort(e.Column, this.listView1.Columns[e.Column].Tag);
//指定排序器并传送列索引与升序降序关键字
this.listView1.Sort();//对列表进行自定义排序
}
\n
{
if (this.listView1.Columns[e.Column].Tag == null)
this.listView1.Columns[e.Column].Tag = true;
bool tabK = (bool)this.listView1.Columns[e.Column].Tag;
if (tabK)
this.listView1.Columns[e.Column].Tag = false;
else
this.listView1.Columns[e.Column].Tag = true;
this.listView1.ListViewItemSorter = new ListViewSort(e.Column, this.listView1.Columns[e.Column].Tag);
//指定排序器并传送列索引与升序降序关键字
this.listView1.Sort();//对列表进行自定义排序
}
\n