I have a couple of listboxes that show alternate row coloring with
If row Mod 2 = 0 And alternateColorBox.Value Then
if (row mod 2)=0 then
g.foreColor = rgb(237,243,254)
g.fillrect 0,0,g.Width,g.height
end if
end if
When the window opens it shows the listboxes with this row coloring. There is checkbox that allows the user to switch between row coloring or just plain (white).
When the checkbox is ticked I use:
For row As Integer = 0 To chapterBox.ListCount-1
For col As Integer = 0 To chapterBox.ColumnCount-1
chapterBox.InvalidateCell(row, col)
Next
Next
A simple .invalidate does not work in Win32. BUT when a Listbox is empty the (re)coloring doesn’t work. How come? Only when there is at least one row. So I use:
[code]
if chapterBox.ListCount = 0 then
chapterBox.AddRow(" ")
For row As Integer = 0 To chapterBox.ListCount-1
For col As Integer = 0 To chapterBox.ColumnCount-1
chapterBox.InvalidateCell(row, col)
Next
Next
chapterBox.DeleteAllRows
else
For row As Integer = 0 To chapterBox.ListCount-1
For col As Integer = 0 To chapterBox.ColumnCount-1
chapterBox.InvalidateCell(row, col)
Next
Next
end if[/code]
How is this possible as the row coloring does work OK when it is opened?
[quote=142383:@Alexander van der Linden]When the checkbox is ticked I use:
For row As Integer = 0 To chapterBox.ListCount-1
For col As Integer = 0 To chapterBox.ColumnCount-1
chapterBox.InvalidateCell(row, col)
Next
Next
A simple .invalidate does not work in Win32. BUT when a Listbox is empty the (re)coloring doesn’t work. How come? Only when there is at least one row. So I use:[/quote]
Maybe you invalidate/recolour only the filled rows? If there are no rows then the For Next loop isn’t executed.
The point with Listbox is that if you use the BackgroundPaint on program start it paints all odd rows even when there is no row data. Just like the Weblistbox.
But if you want to use it again it only functions with a rowcount of 1.
There are many issues related to invalidating a single cell in Windows that don’t work as expected. A few Betas back (2014r1.1 I think it was?) related to this issue in Cocoa, and tried to apply similar fixes to the Windows ListBox code. It did make InvalidateCell work better, but broke many other things unexpectedly so they reverted the Windows code back (Cocoa works great, BTW). So in many cases you need to do what Tim suggested, use InvalidateCell(-1,-1) for Win32.