pythonwxpythonlistctrl

How to use `ListCtrl` on wxpython


How can I append row and it's corresponding data into ListCtrl. I've just finished how to use TreeCtrl(Relatively easier than ListCtrl), it shows me a clear usage of matching single GUI object and data. But ListCtrl dose not.

  1. How can I append or insert single row with it's corresponding data.
  2. How can I access row and it's data
  3. How can I manipulated them (Editing data/row, Deleting data/row)

Can you explain summary of them? Thank you. I know my question is so simple and I can get about this from doc somewhat. I read docs, but still I got no clue


Solution

  • I know that wxPython docs are retarded and gives no much help, here is some quick tips below, i added explanations in comments:

    # create new list control
    listctrl = wx.dataview.DataViewListCtrl( my_panel, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.dataview.DV_SINGLE )
    
    # setup listctrl columns
    listctrl.AppendTextColumn('first name', width=220)  # normal text column
    listctrl.AppendBitmapColumn('my images', 0, width=35)  # you can add images in this col
    listctrl.AppendProgressColumn('Progress', align=wx.ALIGN_CENTER)  # a progress bar
    
    listctrl.SetRowHeight(30)  # define all rows height
    
    # add data, note myList is a list or tuple contains the exact type of data for each columns and same length as col numbers
    listctrl.AppendItem(myList)
    
    # to modify an entry "a single cell located at row x col"
    listctrl.SetValue(myNewValue, row, column)