Grid FreezeTo not working

I don’t undestand why FreezeTo returns False (and does nothing) in this minimal example. I have read the documentation about the limitations of FreezeTo in wx.grid.Grid but I don’t understand which of those limitations I am triggering.

import wx
import wx.grid as grid


class TestFrame(wx.Frame):
    def __init__(self):
        super().__init__(None, title="Freeze rows/columns")

        ROWS = 7
        COLS = 7

        g = grid.Grid(self)
        g.CreateGrid(ROWS, COLS)

        # Populate the grid
        for row in range(ROWS):
            for col in range(COLS):
                g.SetCellValue(row, col, f"{chr(ord('A')+col)}-{1+row}")
        
        self.Sizer = wx.BoxSizer()
        self.Sizer.Add(g, 1, wx.EXPAND)

        frozen = g.FreezeTo(2,1)
        print(frozen)

# Next, create an application object.
app = wx.App()

# Then a frame.
frm = TestFrame()

# Show it.
frm.Show()

Thank you.

Hi,

I tested your code using Python 3.10.6 + wxPython 4.2.1 gtk3 (phoenix) wxWidgets 3.2.2.1 on Linux Mint 21.1 and got the same result.

I noticed another example piece of code elsewhere in which an explicit size was passed to the Grid object constructor, so I tried:

        g = grid.Grid(self, size=(800, 300))

and then the FreezeTo call returned True and appears to be working.

Nice find @RichardT. Thank you. I can confirm that.

you may have to self.Show() before g.FreezeTo :thinking: