Following code sets a cell readonly, but how to set an entire row/column (for example 3rd column) as read only in wx.grid?
import wx.grid as gridlib
myGrid = gridlib.Grid(panel)
myGrid.SetReadOnly(3, 3, True)
You have to use GridCellAttr to do this. Here's a simple example:
import wx
import wx.grid as gridlib
########################################################################
class MyForm(wx.Frame):
""""""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, parent=None, title="A Simple Grid")
panel = wx.Panel(self)
myGrid = gridlib.Grid(panel)
myGrid.CreateGrid(12, 8)
# get the cell attribute for the top left row
editor = myGrid.GetCellEditor(0,0)
attr = gridlib.GridCellAttr()
attr.SetReadOnly(True)
myGrid.SetRowAttr(0, attr)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(myGrid, 1, wx.EXPAND)
panel.SetSizer(sizer)
if __name__ == "__main__":
app = wx.App(False)
frame = MyForm().Show()
app.MainLoop()
This code will make the first row read-only.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With