Wx.ListCtrl with TextEditMixin - disable editing of selected cells

Is it possible to disable the editing of certain cells by the user when using ListCtrl with TextEditMixin ?

I suppose there is a way that Vetos is editing the event, however I cannot find it.

+6
source share
3 answers

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() 
+10
source

As I recall, you need to bind to EVT_LIST_BEGIN_LABEL_EDIT. Then in the event handler you just check which column you are in, and if you are in the column you want to edit, then you do "event.Allow ()", otherwise you use the veto.

+1
source

In wxPython version 4.0.0, the line:

if event.m_col == 1 does not work. Use

if event.GetColumn() == 1

instead.

+1
source

Source: https://habr.com/ru/post/927283/


All Articles