views:

272

answers:

2

I use some wx.ListCtrl classes in wx.LC_REPORT mode, augmented with ListCtrlAutoWidthMixin.

The problem is: When user double clicks the column divider (to auto resize column), column width is set to match the width of contents. This is done by the wx library and resizes column to just few pixels when the control is empty.

I tried calling

self.SetColumnWidth(colNumber, wx.LIST_AUTOSIZE_USEHEADER)

while creating the list, but it just sets the initial column width, not the minimum allowed width.

Anyone succeeded with setting column minimal width?

EDIT: Tried catching

 wx.EVT_LEFT_DCLICK 

with no success. This event isn't generated when user double clicks column divider. Also tried with

wx.EVT_LIST_COL_END_DRAG 

this event is generated, usually twice, for double click, but I don't see how can I retrieve information about new size, or how to differentiate double click from drag&drop. Anyone has some other ideas?

A: 

Ok, after some struggle I got working workaround for that. It is ugly from design point of view, but works well enough for me.

That's how it works:

  1. Store the initial width of column.

    self.SetColumnWidth(colNum, wx.LIST_AUTOSIZE_USEHEADER)

    self.__columnWidth[colNum] = self.GetColumnWidth(c)

  2. Register handler for update UI event.

    wx.EVT_UPDATE_UI(self, self.GetId(), self.onUpdateUI)

  3. And write the handler function.

    def onUpdateUI(self, evt):
    for colNum in xrange(0, self.GetColumnCount()-1):
        if self.GetColumnWidth(colNum) 

The self.GetColumnCount() - 1 is intentional, so the last column is not resized. I know this is not an elegant solution, but it works well enough for me - you can not make columns too small by double clicking on dividers (in fact - you can't do it at all) and double-clicking on the divider after last column resizes the last column to fit list control width.

Still, if anyone knows better solution please post it.

Abgan
+3  A: 

Honestly, I've stopped using the native wx.ListCtrl in favor of using ObjectListView. There is a little bit of a learning curve, but there are lots of examples. This would be of interest to your question.

DrBloodmoney
ObjectListView definitely deserves closer look. Thanks for the info. Due to time constraints I can't use it to solve my current problem, but I really want to use it in my code :-)
Abgan