How to use `ListCtrl` on wxpython

Question:

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

Asked By: Gipyo.Choi

||

Answers:

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)
Answered By: Mahmoud Elshahat

this is what works for me:

import wx

il_icons = wx.ImageList(16, 16, mask=True, initialCount=2)
il_icons.Add(wx.Bitmap('icon01.png'))
il_icons.Add(wx.Bitmap('icon02.png'))

lc_list = wx.ListCtrl(self, wx.ID_ANY, style=wx.LC_REPORT | wx.LC_SINGLE_SEL | wx.LC_EDIT_LABELS | wx.LC_VRULES, name='lc_list')
lc_list.AssignImageList(il_icons, which=wx.IMAGE_LIST_SMALL)
lc_list.AppendColumn('col01', format=wx.LIST_FORMAT_LEFT, width=64)
lc_list.AppendColumn('col02', format=wx.LIST_FORMAT_RIGHT, width=64)
lc_list.Append(('item01',100))
lc_list.Append(('item02',200))
lc_list.SetItemColumnImage(0,0,0)
lc_list.SetItemColumnImage(1,0,1)

lc_list.Bind(wx.EVT_LIST_ITEM_SELECTED, OnItemSelected)

lc_list.Show(True)
Answered By: ivan866
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.