I have a listview control and have some code that sorts the columns, putting a nice little < or > preceeding the name to indicate which direction the sort is in. In this particular listview I have to turn off the sort to requrey the database and re-populate the listview. I wanted to remember the sort column and direction and re-apply the sort to the column they had before. This works GREAT for every column except the very last column. In this scenario I have 4 columns. I've created some integer variables and assign the current values from the listview as follows:

iSortKey = lvwLDAP.SortKey
iSortOrder = lvwLDAP.SortOrder

I then change the sort key back to the first column during the requery:

lvwLDAP.Sorted = True
lvwLDAP.SortKey = 0
lvwLDAP.SortOrder = lvwAscending

My application does its thing, and at the end, I re-apply the sort and alter the column header the sort is on as follows:

lvwLDAP.ColumnHeaders(iSortKey + 1).Text = _
IIf(iSortOrder = lvwAscending, ">" & lvwLDAP.ColumnHeaders(iSortKey + 1).Text, "<" & lvwLDAP.ColumnHeaders(iSortKey + 1).Text)

lvwLDAP.SortKey = iSortKey
lvwLDAP.SortOrder = iSortOrder

When I debug and step through this code it does everything perfectly, EXCEPT when you get on the last column. The values for the .SortKey that gets assigned to iSortKey initially is 0...so when it re-applies it at the end it always sorts on the first column. All the columns sort just as they are supposed to when displaying the data - it is just when I try to save and reapply the sort and, again, only on the last column.