How to dynamically hide/show columns in wxListCtrl with wxColumnSorterMixin and retain sorting. Better way than...?

Hi all,

In a window that uses a wxListCtrl with a wxColumnSorterMixin, I needed to dynamically hide and show a certain number of columns (the last columns of a set).

My code was doing a list.ClearAll() then rebuild and populate all columns. It worked but the sorting was not working after changing the column shown.

So I called wxColumnSorterMinin.__init__ again (after the column number change) to solve the problem, but that did not help either.

wxColumnSorterMinin.__init__ is:

     def __init__(self, numColumns):
         self._colSortFlag = [0] * numColumns
         self._col = -1

         list = self.GetListCtrl()
         if not list:
             raise ValueError, "No wxListCtrl available"
         EVT_LIST_COL_CLICK(list, list.GetId(), self.__OnColClick)

So I added a new wxColumnSorterMinin method:

     def SetColumnCount(self, newNumColumns):
         self._colSortFlag = [0] * newNumColumns
         self._col = -1

Now, i call wxColumnSorterMinin.__init__() once and when I change the columns that are shown I only call xColumnSorterMinin.SetColumnCount()

This works. The columns retain their ability to sort.

Is there a better way?

Thanks

Pierre

Pierre Rouleau wrote:

So I added a new wxColumnSorterMinin method:

    def SetColumnCount(self, newNumColumns):
        self._colSortFlag = [0] * newNumColumns
        self._col = -1

Now, i call wxColumnSorterMinin.__init__() once and when I change the columns that are shown I only call xColumnSorterMinin.SetColumnCount()

This works. The columns retain their ability to sort.

Is there a better way?

Your way makes sense to me.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin, Pierre,

Will the wxColumnSorterMixin be patched/upgraded with this in the next version?

See you
Werner

Robin Dunn wrote:

···

Pierre Rouleau wrote:

So I added a new wxColumnSorterMinin method:

    def SetColumnCount(self, newNumColumns):
        self._colSortFlag = [0] * newNumColumns
        self._col = -1

Now, i call wxColumnSorterMinin.__init__() once and when I change the columns that are shown I only call xColumnSorterMinin.SetColumnCount()

This works. The columns retain their ability to sort.

Is there a better way?

Your way makes sense to me.

Werner F. Bruhin wrote:

Robin, Pierre,

Will the wxColumnSorterMixin be patched/upgraded with this in the next version?

Yep.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!