Sort a listview in .Net

If you have used the Listview class in .Net, you may have noticed that the Listview control does not provide any out of the box sorting capabilities.


But, the ListView control has a property called ListViewItemSorter. If you write a custom class and point this property to this class, the ListView starts sorting all the columns for you.


Below is a cut paste implementation of a ListViewSorter class which is generic and will sort data for you using the default text compare. If you have Date columns then this class may require some tweaking.



Dim ColumnSorter As New ListViewSorter

ListView1.ListViewItemSorter = ColumnSorter



input.JPG ListViewSorter.vb


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s