Columnsort infört i lisview
This commit is contained in:
1
WinFormDi/frmPayments.Designer.cs
generated
1
WinFormDi/frmPayments.Designer.cs
generated
@ -53,6 +53,7 @@
|
||||
lvPayments.TabIndex = 0;
|
||||
lvPayments.UseCompatibleStateImageBehavior = false;
|
||||
lvPayments.View = View.Details;
|
||||
lvPayments.ColumnClick += lvPayments_ColumnClick;
|
||||
//
|
||||
// ch1_Id
|
||||
//
|
||||
|
||||
@ -14,6 +14,8 @@ namespace WinFormDiApp
|
||||
{
|
||||
public partial class frmPayments : Form
|
||||
{
|
||||
private ListViewColumnSorter lvwColumnSorter;
|
||||
|
||||
private bool _enableClearing;
|
||||
private bool _enableDetailShow;
|
||||
private readonly IAccountRecordRepository _accountRecordRepository;
|
||||
@ -45,6 +47,13 @@ namespace WinFormDiApp
|
||||
public frmPayments(IAccountRecordRepository accountRecordRepository)
|
||||
{
|
||||
InitializeComponent();
|
||||
//---------------------------------
|
||||
// Create an instance of a ListView column sorter and assign it
|
||||
// to the ListView control.
|
||||
lvwColumnSorter = new ListViewColumnSorter();
|
||||
lvPayments.ListViewItemSorter = lvwColumnSorter;
|
||||
//---------------------------------
|
||||
|
||||
lvPayments.Items.Clear();
|
||||
_accountRecordRepository = accountRecordRepository;
|
||||
}
|
||||
@ -119,6 +128,32 @@ namespace WinFormDiApp
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void lvPayments_ColumnClick(object sender, ColumnClickEventArgs e)
|
||||
{
|
||||
// Determine if clicked column is already the column that is being sorted.
|
||||
if (e.Column == lvwColumnSorter.SortColumn)
|
||||
{
|
||||
// Reverse the current sort direction for this column.
|
||||
if (lvwColumnSorter.Order == SortOrder.Ascending)
|
||||
{
|
||||
lvwColumnSorter.Order = SortOrder.Descending;
|
||||
}
|
||||
else
|
||||
{
|
||||
lvwColumnSorter.Order = SortOrder.Ascending;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Set the column number that is to be sorted; default to ascending.
|
||||
lvwColumnSorter.SortColumn = e.Column;
|
||||
lvwColumnSorter.Order = SortOrder.Ascending;
|
||||
}
|
||||
|
||||
// Perform the sort with these new sort options.
|
||||
lvPayments.Sort();
|
||||
}
|
||||
//------------------------------------------------- sorting ------------
|
||||
|
||||
//------------------------------------------------- sorting ------------
|
||||
|
||||
Reference in New Issue
Block a user