I have a ListView control on a tab page. The backcolor of the items of the ListView are changed according to certain criteria, but whether or not the backcolor changes appears to be pretty random.
The tab page containing the ListView is not the default tab page on application startup. On application startup, the ListView is updated. It displays a list of documents populated from a text file (which contains the list of documents and information such as most recent update time) and then changes the backcolor according to the most recent update time. The ListView is also updated every time the user enters the containing tab page.
In debug mode, the backcolors display as intended every time. When actually running the application, however, the colours don't appear immediately about 60% of the time. Let me explain more. There are about 500 items in the ListView so a vertical scrollbar is necessary to view them all. Upon entering the containing tab page, the backcolor of the visible items is white. Scrolling down reveals further items, but they are coloured properly. Scrolling back up reveals all of the items to be coloured properly.
I'm out of ideas as to what could be causing this. I've tried a ListView.Refresh() statement at the end of the method that populates and colours the ListView, but to no avail (this fixed it in debug mode, but not in the published application - yes, it did update).
Currently the method that colours the ListView is something like the below. Please note that the arrays documentNames and documentUpdates, and the item collection of ListView are all linked so that item x in ListView has the name at position x in documentNames and was most recently updated on the date at position x in documentUpdates.
Friend Sub ListViewUpdate()
Dim initialised As Boolean = False
While Not initialised
ListView.Items.Clear()
' Iterate through files in the containing directory and add document names to
' an array, documentNames
' Sort documentNames alphanumerically
' Find the date of the most recent change to each document and store it in the
' appropriate element of another array, documentUpdates
' Populate the ListView with the elements from documentNames
' Colour each item in ListView according to the difference between the current
' date and the date stored in the corresponding element of documentUpdates
initialised = True
ListView.Refresh()
End While
End Sub
Any advice that could help me fix this (not disastrous, but annoying) bug would be appreciated! I can provide more detailed code if needed.