Your problem is that your list of items starts off with item [0] so
when you do current_items = GetCount it is set to 3 then you try to
delete item[3] out of a set of item[0], item[1], item[2] - and get a
message that there is no item[3] - not too surprising really.
···
On 23/01/13 07:50, Priyank Khare wrote:
My code is generating following error- *** “Couldn’t
retrieve information about list control item 3”***.
import wx DATA = [("0", "Zero"), ("1", "One"), ("2", "Two")] class MainWindow(wx.Frame): def __init__(self, *args, **kwargs): wx.Frame.__init__(self, *args, **kwargs ) self.panel = wx.Panel(self) self.list = wx.ListCtrl(self.panel, style=wx.LC_REPORT) self.list.InsertColumn(0, "Index") self.list.InsertColumn(1, "Number") for data in DATA: self.list.Append((data[0], data[1])) self.button = wx.Button(self.panel, label="Delete") self.button.Bind(wx.EVT_BUTTON, self.OnButton) self.sizer = wx.BoxSizer(wx.VERTICAL) self.sizer.Add(self.list, 1, wx.ALL | wx.EXPAND, 5) self.sizer.Add(self.button, 0, wx.ALL | wx.EXPAND, 5) self.panel.SetSizerAndFit(self.sizer) self.Show() def OnButton(self, e): current_items = self.list.GetItemCount() while ((current_items) >= 0) : if (self.list.GetItemText(current_items) == "1" or self.list.GetItemText(current_items-1) == "2"): self.list.DeleteItem(current_items) wx.MessageBox("Delete item ", 'Delete Information',wx.OK) else: break current_items-=1 if __name__ == "__main__": app = wx.App(False) win = MainWindow(None) win.Centre() app.MainLoop()
Can anyone tell me what is wrong with the code? And what should i do to resolve this error?
Thanks in advance.
–
-- To unsubscribe, send email to
or visit
–
Steve Gadget Barnes
wxPython-users+unsubscribe@googlegroups.com
http://groups.google.com/group/wxPython-users?hl=en