Virus
Virus

Reputation: 61

Deleting from listctrl in python

I want to delete an item from '0'th index in a (python) list control. In my application the items are being deleted from more than '0'th index, but the '0'th index is not being deleted. There is no error reported by my code.

For example:- There is a list of following data; 0 keydown(key+ctrl)
1 wait(0.21) 2 click(....) 3 wait(1.25) and so on

So I want to delete the 1st line from the list control. In this example 0,1,2,3 are just list index numbers of list controls.

Thanks in advance!

Upvotes: 2

Views: 4953

Answers (1)

Fenikso
Fenikso

Reputation: 9451

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, "#")
        self.list.InsertColumn(1, "Number")       
        for data in DATA:
            self.list.Append((data[0], data[1]))

        self.button = wx.Button(self.panel, label="Delete index 0")
        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):
        self.list.DeleteItem(0)


if __name__ == "__main__":
    app = wx.App(False)
    win = MainWindow(None)
    app.MainLoop()

Upvotes: 4

Related Questions