progress update in a listbox

I’m trying to implement a progress bar in column 1 of a 2 column listbox (column one being actually the second column… first = 0 second=1 of course) using the CellTextPaint event with the following code:

Select Case column
Case 1
    g.ForeColor = &c006600
    g.FillRect(2, 2, g.Width-2, g.Height-4)
    g.ForeColor = &c00ff00
    g.FillRect(2, 2, (g.Width-2)*(myProgress/100), g.Height-4)
    return True
end Select

myProgress is a public property

Additionally, the listbox Open event adds a row to the listbox with me.AddRow and then calls a method, AllEditable, that sets all cells to editable:

for i as integer = 0 to Listbox1.ColumnCount-1
    for j as integer = 0 to Listbox1.LastIndex
        Listbox1.CellType(j,i)=Listbox.TypeEditableTextField
    next
next

I have a timer (mode2 period=10) in the same window with the following in the Action event:

myProgress = myProgress + 1
if myProgress > 100 then myProgress = 0
ProgressBar1.Value = myProgress

the ProgressBar1 control is a separate control on the window that I’m using to troubleshoot the fact that updates are actually occurring.

THE PROBLEM: The cellTextPaint event does not update on Windows (Windows 7) unless you do something like resize the window, while the standalone progress bar does update appropriately. On the Mac, both progress bars… the standalone one as well as the CellTextPaint event one… do update correctly. What have I forgotten in order to make this work on Windows?

Windows 7, Xojo 2014r1.1 Desktop Version

You should use .invalidate in the timer to update the content.

Invalidate will not update the cells (on Windows). Use InvalidateCell() in the timer to cause the listbox to update.

Thanks Tim, that worked exactly as intended. The code for the timer is updated as follows:

myProgress = myProgress + 1
if myProgress >= 100 then myProgress = 0
ProgressBar1.Value = myProgress 
  
//cycle through Listbox1 rows and invalidate column 1
for i as integer = 0 to Listbox1.ListCount-1
    Listbox1.InvalidateCell(i,1)
next

Bug report?

ummmmm… hmmmmm… I don’t see that as a bug. AS much as it pains me to admit, I think it was a lack of understanding on my part :slight_smile: This lack of understanding was kindly corrected by the existence of this forum and specifically Tim, above. wooot wooot!

you can also remove the FOR/NEXT LOOP and just say

 Listbox1.InvalidateCell(-1,-1)