1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace ListViewNativeArrowIconPoC
- {
- public partial class WinformPocForm : Form
- {
- private readonly ColumnSorter _lstColumnSorter = new ColumnSorter();
- public WinformPocForm()
- {
- InitializeComponent();
- MainListView.ListViewItemSorter = _lstColumnSorter;
- }
- private void MainListView_ColumnClick(object sender, ColumnClickEventArgs e)
- {
- var listView = (ListView)sender;
- // Determine if clicked column is already the column that is being sorted.
- if (e.Column == _lstColumnSorter.SortColumn)
- {
- // Reverse the current sort direction for this column.
- _lstColumnSorter.Order =
- _lstColumnSorter.Order == SortOrder.Ascending
- ? SortOrder.Descending
- : SortOrder.Ascending;
- }
- else
- {
- // Set the column number that is to be sorted; default to ascending.
- _lstColumnSorter.SortColumn = e.Column;
- _lstColumnSorter.Order = SortOrder.Ascending;
- }
- // Perform the sort with these new sort options.
- listView.Sort();
- listView.SetSortIcon(_lstColumnSorter.SortColumn, _lstColumnSorter.Order);
- }
- }
- }
|