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.
···
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.
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:
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.
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.
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).
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.
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:
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: