Cells don't appear to be updating within a loop?

34 Views Asked by At

I'm trying to update a wxgrid with values read from a database.

When I use SetCellValue directl above my loop, it correctly assigns the value, but within the loop it only appears to update a 'local'copy of the grid, and when out of the loop again, only contains the values it had previously - I'm sure this is a real silly mistake on my behalf, but its driving me mad so really appreciate any assistance.

    #now clear grid and re-populate with cafe data
    print('1,6 is ',self.myGrid.GetCellValue(1,6))   
    self.myGrid.SetCellValue(1,7,'TEST')     
    #self.myGrid.ClearGrid()
    for index, value in enumerate(curItems):
        x = 0
        print(index)
        print(len(value))
        while x < len(value):
            if debug : print(x,index,value[x])
            self.myGrid.SetCellValue(x,index,str(value[x]))
            print('grid values :',index,x,self.myGrid.GetCellValue(x,index))
            x += 1
    print('1,7 is ',self.myGrid.GetCellValue(1,7))
    self.myGrid.ForceRefresh

cell (1,6) is defined with a test value in the definition function before this gets called on an event (which updates other setLabels etc fine), and gives the correct value here:

1,6 is  I'm in red!

within the loop the values are set correctly:

grid values : 1 0 20220114002
grid values : 1 1 2022-01-14
grid values : 1 2 Electrical
grid values : 1 3 Toaster
grid values : 1 4 burns
grid values : 1 5 0
grid values : 1 6 Not Fixed
grid values : 1 7 Steve
grid values : 1 8 too damaged
grid values : 1 9 1

but as soon as you come back out of the loop:

1,7 is  TEST
1

There are 1 best solutions below

1
eya46 On

Maybe 'index' and 'x' are in the wrong place

self.myGrid.SetCellValue(index,x,str(value[x]))
print('grid values :',index,x,self.myGrid.GetCellValue(index,x))