Using a wx.ListCtrl with checkboxes and a checkbox in the header column

Hi all,

I've read the documentation in regards to creating a list control with
checkboxes in every row such that a class defined as:

class TestListCtrl(wx.ListCtrl, listmix.CheckListCtrlMixin,
listmix.ListCtrlAutoWidthMixin):
    def __init__(self, *args, **kwargs):
        wx.ListCtrl.__init__(self, *args, **kwargs)
        listmix.CheckListCtrlMixin.__init__(self)
        listmix.ListCtrlAutoWidthMixin.__init__(self)

will insert a checkbox everytime a call to Append is made.

However, I cannot figure out how to get a checkbox into the header
column. I want to introduce a checkbox, that when selected will
select all the items in the list control and vice versa.

In other words I want to do something akin to:

select_all_cb = wx.CheckBox(self, -1)
self.InsertColumn(0, select_all_cb)

Is this possible?

Thanks

Hi,

···

On Wed, Nov 23, 2011 at 5:42 PM, Rish rishsharma@gmail.com wrote:

Hi all,

I’ve read the documentation in regards to creating a list control with

checkboxes in every row such that a class defined as:

class TestListCtrl(wx.ListCtrl, listmix.CheckListCtrlMixin,

listmix.ListCtrlAutoWidthMixin):

def __init__(self, *args, **kwargs):

    wx.ListCtrl.__init__(self, *args, **kwargs)

    listmix.CheckListCtrlMixin.__init__(self)

    listmix.ListCtrlAutoWidthMixin.__init__(self)

will insert a checkbox everytime a call to Append is made.

However, I cannot figure out how to get a checkbox into the header

column. I want to introduce a checkbox, that when selected will

select all the items in the list control and vice versa.

In other words I want to do something akin to:

select_all_cb = wx.CheckBox(self, -1)

self.InsertColumn(0, select_all_cb)

Is this possible?

Thanks

I’m not sure. You might be able to draw it on there and handle it that way using a wx.DC. However, I am pretty sure you could do that with the UltimateListCtrl. Check the demo out and see if it can do what you want.

Mike Driscoll

Blog: http://blog.pythonlibrary.org

You can put icons on the headers so you can have a checkbox by swapping images similarly to how the CheckListCtrlMixin does it for the rows. There is an extra helper function added on to wx.ListCtrl by wxPython called SetColumnImage that does the work for you. There is also a ClearColumnImage if you want to get rid of it.

     def SetColumnImage(self, col, image):
         item = self.GetColumn(col)
         # preserve all other attributes too
         item.SetMask( wx.LIST_MASK_STATE |
                       wx.LIST_MASK_TEXT |
                       wx.LIST_MASK_IMAGE |
                       wx.LIST_MASK_DATA |
                       wx.LIST_SET_ITEM |
                       wx.LIST_MASK_WIDTH |
                       wx.LIST_MASK_FORMAT )
         item.SetImage(image)
         self.SetColumn(col, item)

     def ClearColumnImage(self, col):
         self.SetColumnImage(col, -1)

···

On 11/23/11 3:42 PM, Rish wrote:

Hi all,

I've read the documentation in regards to creating a list control with
checkboxes in every row such that a class defined as:

class TestListCtrl(wx.ListCtrl, listmix.CheckListCtrlMixin,
listmix.ListCtrlAutoWidthMixin):
     def __init__(self, *args, **kwargs):
         wx.ListCtrl.__init__(self, *args, **kwargs)
         listmix.CheckListCtrlMixin.__init__(self)
         listmix.ListCtrlAutoWidthMixin.__init__(self)

will insert a checkbox everytime a call to Append is made.

However, I cannot figure out how to get a checkbox into the header
column. I want to introduce a checkbox, that when selected will
select all the items in the list control and vice versa.

In other words I want to do something akin to:

select_all_cb = wx.CheckBox(self, -1)
self.InsertColumn(0, select_all_cb)

Is this possible?

--
Robin Dunn
Software Craftsman