Conditional Formatting a Listbox - refining it
I have found a method of doing conditional formating a listbox to the individual field using subitem code as follows (not the complete code however you'll get the entire idea as its copied from a website tutorial)
I've played with it enough times to see that it works thoroughly, even though most say its not possible to do it.
With Me.ListView1
For Counter = 1 To Me.ListView1.ListItems.Count
Set Item = Me.ListView1.ListItems.Item(Counter)
' Set the variable to the amount
Amount = Item.SubItems(4)
If Amount <= 500 Or Amount <= 1000 Then
.ListItems.Item(Counter).ForeColor = vbRed
.ListItems.Item(Counter).ListSubItems(1).ForeColor = vbRed
.ListItems.Item(Counter).ListSubItems(2).ForeColor = vbRed
.ListItems.Item(Counter).ListSubItems(3).ForeColor = vbRed
.ListItems.Item(Counter).ListSubItems(4).ForeColor = vbRed
else
'duplicated just make it vbBlack
.ListItems.Item(Counter).ForeColor = vbBlack
.ListItems.Item(Counter).ListSubItems(1).ForeColor = vbBlack
.ListItems.Item(Counter).ListSubItems(2).ForeColor = vbBlack
.ListItems.Item(Counter).ListSubItems(3).ForeColor = vbBlack
.ListItems.Item(Counter).ListSubItems(4).ForeColor = vbBlack
end if
Next Counter
Me.ListView1.Refresh
The only thing i would prefer is to make the background instead the colour rather than the text as even making them individually bold isn't really effective enough. A coloured box or the equivalent, such as highlight, would be far better.
My question is can anyone point me in the direction of the syntax and options that all work with this code as the website isn't responding to questions on it.
The code is dependent on an unusual reference being loaded - Microsoft Common Controls 6.0(SP6) - MSCOMCTL.OCX
|