Hi all,
let’s me explain my situation.
I have an EditableListCtrl in a panel and I would have a list with two colums.
In particular, the item in the first column can not be modified.
At the bottom of this post there is a little pice of code.
I’m able to create and populate the list and also to edit the items in the second colum.
Anyway, I am facing a strange bug:
if it is the first time that I try to edit the list and I try to edit the second column of the first item, I’m not able to correctly menage this situation.
In fact, in this case I get -1 in the variable “focusedRow” of the OnItemEdited function.
I have no problem when I try to modify whatever items belonging to the second column of whaterver row, except the first one.
If I edit a row different from the first one, then I have no problem with the first row.
I’m using wxpython 3.0.2.0 and python 2.7.10.
Any idea?
Thank you vevry much.
Robert
class EditableListCtrl(wx.ListCtrl, listmix.CheckListCtrlMixin, 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)
listmix.CheckListCtrlMixin.__init__(self)
self.parent = parent
def OnCheckItem(self, index, flag):
event = self.parent.CheckModifyEvent(ind=index, flagCheck=flag)
wx.PostEvent(self.parent, event)
class something():
# OTHER CODE
def ShowPanel(self):
self.Panel = wx.Dialog(self.parent, style = wx.ID_OK|wx.DEFAULT_DIALOG_STYLE)
self.Panel.CheckModifyEvent, self.Panel.EVT_CHECKMODIFY = wx.lib.newevent.NewEvent()
self.ListCtrl = EditableListCtrl(self.Panel, style=wx.LC_REPORT|wx.BORDER_SUNKEN)
self.ListCtrl.InsertColumn(0, 'Col 1')
self.ListCtrl.InsertColumn(1, 'Col 2')
self.ListCtrl.Bind(wx.EVT_LIST_END_LABEL_EDIT, self.OnItemEdited)
self.ListCtrl.Bind(wx.EVT_LIST_BEGIN_LABEL_EDIT, self.OnStartingEditing)
for i, itemForList in enumerate(self.itemsForList):
self.ListCtrl.InsertStringItem(i, itemForList[0])
self.ListCtrl.SetStringItem(i, 1, itemForList[1])
# OTHER CODE FOR VISUALIZATION
def OnStartingEditing(self, evt):
if evt.m_col == 0:
evt.Veto()
else:
evt.Skip()
def OnItemEdited(self, evt):
focusedRow = int(self.ListCtrl.GetFocusedItem())
if evt.GetLabel() != "":
self.ListCtrl.ToggleItem(focusedRow)
# DO SOME OTHER STUFF
``