Show/Hide ListCtrl Column(s) in report mode

Hello all,

Like many people before me, I have a wx.ListCtrl and would like to give the user the ability to show/hide columns within it. What I have currently is a ListCtrl and have bound an event handler to wx.EVT_LIST_COL_RIGHT_CLICK so that when the user right-clicks on a column they are presented with a wxMenu containing a check item for each column header. Some googling shows that a common approach to hide a column is to set the width to 0, however, this comes with a two specific issues:
    1. The user can un-hide the column by resizing the 0 width column
    2. Doing #1 mangles the state of the wxMenu check items.

Another approach I tested was to delete via ListCtrl.DeleteColumn() and re-insert the column via ListCtrl.InsertColumn() or ListCtrl.InsertItem(). Neither of these worked as expected because the underlying data was removed when the column was deleted.

So, does anybody have a suggestion as to how to accomplish this in an elegant way? My feeling is that there is no way to get around having to re-load the data every time a column is added or removed.

Thank you,

-Dave

If you use the wx.LC_VIRTUAL style then the listctrl will ask you (via overridden callback methods) for the values as they are needed for display. IOW you do not load all the values into the listctrl when you create it, so if you delete a column and add it again later you still have the data available to display in that column. You'll just want to come up with a good way to map your data values to the rows/cols of the listctrl that takes into account that some data cols may not have active listctrl cols.

···

On 7/13/11 7:42 AM, dtp lists wrote:

Hello all,

     Like many people before me, I have a wx.ListCtrl and would like to
give the user the ability to show/hide columns within it. What I have
currently is a ListCtrl and have bound an event handler to
wx.EVT_LIST_COL_RIGHT_CLICK so that when the user right-clicks on a
column they are presented with a wxMenu containing a check item for each
column header. Some googling shows that a common approach to hide a
column is to set the width to 0, however, this comes with a two specific
issues:
         1. The user can un-hide the column by resizing the 0 width column
         2. Doing #1 mangles the state of the wxMenu check items.

Another approach I tested was to delete via ListCtrl.DeleteColumn() and
re-insert the column via ListCtrl.InsertColumn() or
ListCtrl.InsertItem(). Neither of these worked as expected because the
underlying data was removed when the column was deleted.

So, does anybody have a suggestion as to how to accomplish this in an
elegant way? My feeling is that there is no way to get around having to
re-load the data every time a column is added or removed.

--
Robin Dunn
Software Craftsman

Another possibility would be to use UltimateListCtrl in wx.lib.agw,
which allows hiding/showing columns by calling
SetColumnShown(column_number, show=True). More docs:

http://xoomer.virgilio.it/infinity77/AGW_Docs/ultimatelistctrl.UltimateListCtrl.html

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/

···

On 13 July 2011 19:57, Robin Dunn wrote:

On 7/13/11 7:42 AM, dtp lists wrote:

Hello all,

Like many people before me, I have a wx\.ListCtrl and would like to

give the user the ability to show/hide columns within it. What I have
currently is a ListCtrl and have bound an event handler to
wx.EVT_LIST_COL_RIGHT_CLICK so that when the user right-clicks on a
column they are presented with a wxMenu containing a check item for each
column header. Some googling shows that a common approach to hide a
column is to set the width to 0, however, this comes with a two specific
issues:
1. The user can un-hide the column by resizing the 0 width column
2. Doing #1 mangles the state of the wxMenu check items.

Another approach I tested was to delete via ListCtrl.DeleteColumn() and
re-insert the column via ListCtrl.InsertColumn() or
ListCtrl.InsertItem(). Neither of these worked as expected because the
underlying data was removed when the column was deleted.

So, does anybody have a suggestion as to how to accomplish this in an
elegant way? My feeling is that there is no way to get around having to
re-load the data every time a column is added or removed.

If you use the wx.LC_VIRTUAL style then the listctrl will ask you (via
overridden callback methods) for the values as they are needed for display.
IOW you do not load all the values into the listctrl when you create it, so
if you delete a column and add it again later you still have the data
available to display in that column. You'll just want to come up with a
good way to map your data values to the rows/cols of the listctrl that takes
into account that some data cols may not have active listctrl cols.

Andrea,

The UltimateListCtrl is exactly what I was looking for! Thank you so much. One quick question regarding the column header height... is that adjustable somehow? The native wx.ListCtrl has a very thin header while the ultimatelistctrl has a slightly thicker one. There does not seem to be a straightforward way to resize the header hight via the API.

Thanks again,

-Dave

···

On Thu, Jul 14, 2011 at 5:16 AM, Andrea Gavana andrea.gavana@gmail.com wrote:

On 13 July 2011 19:57, Robin Dunn wrote:

On 7/13/11 7:42 AM, dtp lists wrote:

Hello all,

Like many people before me, I have a wx.ListCtrl and would like to

give the user the ability to show/hide columns within it. What I have

currently is a ListCtrl and have bound an event handler to

wx.EVT_LIST_COL_RIGHT_CLICK so that when the user right-clicks on a

column they are presented with a wxMenu containing a check item for each

column header. Some googling shows that a common approach to hide a

column is to set the width to 0, however, this comes with a two specific

issues:

    1. The user can un-hide the column by resizing the 0 width column
    2. Doing #1 mangles the state of the wxMenu check items.

Another approach I tested was to delete via ListCtrl.DeleteColumn() and

re-insert the column via ListCtrl.InsertColumn() or

ListCtrl.InsertItem(). Neither of these worked as expected because the

underlying data was removed when the column was deleted.

So, does anybody have a suggestion as to how to accomplish this in an

elegant way? My feeling is that there is no way to get around having to

re-load the data every time a column is added or removed.

If you use the wx.LC_VIRTUAL style then the listctrl will ask you (via

overridden callback methods) for the values as they are needed for display.

IOW you do not load all the values into the listctrl when you create it, so

if you delete a column and add it again later you still have the data

available to display in that column. You’ll just want to come up with a

good way to map your data values to the rows/cols of the listctrl that takes

into account that some data cols may not have active listctrl cols.

Another possibility would be to use UltimateListCtrl in wx.lib.agw,

which allows hiding/showing columns by calling

SetColumnShown(column_number, show=True). More docs:

http://xoomer.virgilio.it/infinity77/AGW_Docs/ultimatelistctrl.UltimateListCtrl.html

Andrea.

“Imagination Is The Only Weapon In The War Against Reality.”

http://xoomer.alice.it/infinity77/

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

There isn't actually a way to do it, the header height is pulled out
using wx.RendererNative:

wx.RendererNative.Get().GetHeaderButtonHeight(listctrl)

But it should be easy enough to add. If you can enter a bug report on
wxTrac that would be most helpful, so that I don't lose track of this
improvement (component=AGW).

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/

==> Never *EVER* use RemovalGroup for your house removal. You'll
regret it forever.
The Doomed City: Removal Group: the nightmare <==

···

On 15 July 2011 00:00, dtp lists wrote:

Andrea,

The UltimateListCtrl is exactly what I was looking for\! Thank you so

much. One quick question regarding the column header height... is that
adjustable somehow? The native wx.ListCtrl has a very thin header while the
ultimatelistctrl has a slightly thicker one. There does not seem to be a
straightforward way to resize the header hight via the API.

Hi,

Andrea,

The UltimateListCtrl is exactly what I was looking for\! Thank you so

much. One quick question regarding the column header height... is that
adjustable somehow? The native wx.ListCtrl has a very thin header while the
ultimatelistctrl has a slightly thicker one. There does not seem to be a
straightforward way to resize the header hight via the API.

There isn't actually a way to do it, the header height is pulled out
using wx.RendererNative:

wx.RendererNative.Get().GetHeaderButtonHeight(listctrl)

But it should be easy enough to add. If you can enter a bug report on
wxTrac that would be most helpful, so that I don't lose track of this
improvement (component=AGW).

No need for a bug report, I just committed a fix in SVN which allows
to set a custom value for the header and footer height
(independently). You can now simply use:

list_control.SetHeaderHeight(30)

And it will do the job.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/

==> Never *EVER* use RemovalGroup for your house removal. You'll
regret it forever.
The Doomed City: Removal Group: the nightmare <==

···

On 22 July 2011 00:33, Andrea Gavana wrote:

On 15 July 2011 00:00, dtp lists wrote: