Search code examples
pythonlistviewwxpython

wx.ListCtrl with TextEditMixin - Disable Editing of Selected Cells


Is there any way to disable the editing of specific cells by the user when using ListCtrl with TextEditMixin?

I guess there's some way that Vetos the editing event, however I can't find it.


Solution

  • Event wx.EVT_LIST_BEGIN_LABEL_EDIT:

    class EditableListCtrl(wx.ListCtrl, listmix.TextEditMixin):
        def __init__(self, parent, ID=wx.ID_ANY, pos=wx.DefaultPosition,
                     size=wx.DefaultSize, style=0):
            wx.ListCtrl.__init__(self, parent, ID, pos, size, style)
            listmix.TextEditMixin.__init__(self)
            self.Bind(wx.EVT_LIST_BEGIN_LABEL_EDIT, self.OnBeginLabelEdit)
    
        def OnBeginLabelEdit(self, event):
            if event.m_col == 1:
                event.Veto()
            else:
                event.Skip()