Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Colorize listview with API sort

Status
Not open for further replies.

MattSTech

Programmer
Apr 10, 2003
333
US
I am having a bit of trouble colorizing a listview sorted with strongm's API sorting of a listview used in thread222-578008. The colorizing code turns negative numbers red and positive numbers green. It works swimmingly for standard alphabetic sorting, but when the API sorting is used, it colorizes them wrong.
I am guessing the problem lies with the way I am parsing through the listview. I notice the first entry in the loop is really item 200 in the list. However, when I apply the color, it is applying it to the first visible item in the list, not item 200. Either this is very tricky or very simple, I am just not figuring it out. Thanks in advance for the help.

My code for colorizing is:
Code:
Private Sub ColorizeEntries()
Dim i As Integer
    For i = 1 To lstvwList.ListItems.Count
        If lstvwList.ListItems(i).SubItems(4) > 0 Then
            lstvwList.ListItems(i).ListSubItems(4).ForeColor = &H8000&
        Else
            lstvwList.ListItems(i).ListSubItems(4).ForeColor = &HC0&
        End If
    Next
    lstvwList.Refresh
End Sub

 
Hmm - that is interesting. I see what you mean. Might need to look into this a little further.
 
I have tried many things to remedy this, but I have resigned to putting the sort in the DB query and hitting the DB each time.
My dataset is rather small, so it is not too bad doing it this way. Let me know if you come up with something.
Matt
 
I'm still musing on this. The documentation is not explicit, but it would appear that the ListView internally maintains a display order list that differs from the ListItems collection, and the LVM_SORTITEMS message does not keep these in synch. I'm wondering if LVM_SORTITEMSEX might resolve this, but have not tried playing with it yet
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top