ListView Sorting

C

Curtis

I am trying to do a simple sort on a list view.With the listview control the
first time I sort on the control it sorts the items but anytime after that
it fails to sort. I'm sure this is a simple answer but anyways here is my
code any help would be greatly apperciated.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
lvTest.Items.Add("1001")
lvTest.Items.Add("5000")
lvTest.Items.Add("1002")
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
lvTest.Sorting = SortOrder.Descending
lvTest.Sort()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
lvTest.Sorting = SortOrder.Ascending
lvTest.Sort()
End Sub

Thanks,
Curtis
 
P

Peter Proost

Hi, I think you need to have a column and view set to details for it to work
as you want. If you have a column and view set to details you can order the
listview by calling lvTest.Sorting = SortOrder.Descending or
lvTest.Sorting = SortOrder.Ascending, then there's no need to call
lvTest.Sort

Hth greetz Peter
 
C

Curtis

well, I would like my list to use the LargeIcon view. So does this mean I
have to write some type of custom class to handle the sorting that
implements IComparable or is there a simpler way of sorting a listView
control that is using the largeIcon view. I simply want to sort by the
ListView Item Text either by descending or ascending.

Thanks,
Curtis
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top