1

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

3
  • your question is too broad. Besides on Stackoverflow you should show your code , full error message and then we can try to resolve this problem. Commented Apr 22, 2019 at 4:41
  • This is a request for a full tutorial rather than a question Commented Apr 22, 2019 at 8:57
  • try this blog.pythonlibrary.org/2011/01/04/… Commented Apr 22, 2019 at 9:04

2 Answers 2

2

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)
Sign up to request clarification or add additional context in comments.

3 Comments

Seems, data and it's cell's label is somewhat irrelevant right? Looks data attachment and label attachment is working different ways.
Right, labels are nothing, the whole thing works more like Microsoft Excel, where you can access cel by its location (row, column) or just past a whole row, just be careful when you add a row, the number of items must match the columns count otherwise you will get a weird behavior or errors
So I can access specific rows data by label index if I put data and label carefully.(Order of row and data's index should be same)
0

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.