| |

VerySource

 Forgot password?
 Register
Search
View: 685|Reply: 2

Listview sorting problem (anxious)

[Copy link]

4

Threads

7

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-1-14 12:20:01
| Show all posts |Read mode
I would like to ask how to achieve click on the title of each column of the listview, this column is automatically sorted.
Reply

Use magic Report

0

Threads

56

Posts

21.00

Credits

Newbie

Rank: 1

Credits
21.00

 China

Post time: 2020-1-18 22:54:01
| Show all posts
I have encountered this problem before, the post code is for reference only ~~

// Define a comparator class for sorting and implement the IComparer interface
public class ListViewItemComparer: IComparer
{
private int col;
public ListViewItemComparer ()
{
col = 0;
}
public ListViewItemComparer (int column)
{
col = column;
}
public int Compare (object x, object y)
{
return String.Compare (((ListViewItem) x) .SubItems [col] .Text, ((ListViewItem) y) .SubItems [col] .Text);
}
}
// Event handling
private void processList_ColumnClick (object sender, System.Windows.Forms.ColumnClickEventArgs e)
{
ListView1.ListViewItemSorter = new ListViewItemComparer (e.Column);
ListView1.Sort ();
}
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-24 13:00:02
| Show all posts
mark
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list