Get column number or value in wx.ListControl wxPython

590 Views Asked by At

How to get column number or value in wx.ListControl wxPython? I want to sort the item by column when I click it. I'm using BoaConstructor IDE. Please help me :)

3

There are 3 best solutions below

0
On

To get the value of the first (0) column header:

rowid = self.list_ctrl.GetColumn(0)
print (rowid.GetText())

To be able to sort the listctrl read up on wx.lib.mixins.listctrl
https://wxpython.org/Phoenix/docs/html/wx.lib.mixins.listctrl.html

1
On

Its been a while since I have used wxPython, but I some methods to obtain item data from a listctrl are:

0
On

Thank you for all of your answers. I've found the way to do it. When the column is clicked, it will return the value of the column header. This is what I want.

noCol = event.m_col
n = self.lc.GetColumn(noCol).GetText()
print(n)