I have a wxListCtrl that is virtual (due to tens of thousands of rows) with each row having custom row colors I am setting with OnGetItemColumnAttr().
The wxListCtrl is also configured for single selection.
The row/column colors work fine except the current selected row displays with the default row background color and default text color.
In my OnGetItemColumnAttr() I explicitly check for the requested row/column being from the selected row and supply colors intended to indicate the row being selected - but OnGetItemColumnAttr() is not called for the columns in the selected row - it just uses the default colors.
Is there a separate handler/callback for setting the item column attributes for the selected row/columns?
Note: the only place I've seen mention of wxListCtrl's OnGetItemColumnAttr() is in these discussion forums & StackOverflow. Are the various callbacks/handlers/virtual-overrides for wxListCtrl better described anywhere? The wxListCtrl sample is complex and dense enough to be a mini-research project all by itself...
wxListCtrl & OnGetItemColumnAttr() & the selected row Topic is solved
Re: wxListCtrl & OnGetItemColumnAttr() & the selected row
AFAIK the "selected" colors can't be overriden.
One idea (untested): Maybe you can avoid that any row gets selected (from the native control's point of view) by consuming the left mouse click, and instead handle the selection state yourself. Then you regain control over its colors.
They're all in the documentation and there aren't any hidden ones.Note: the only place I've seen mention of wxListCtrl's OnGetItemColumnAttr() is in these discussion forums & StackOverflow. Are the various callbacks/handlers/virtual-overrides for wxListCtrl better described anywhere?
One idea (untested): Maybe you can avoid that any row gets selected (from the native control's point of view) by consuming the left mouse click, and instead handle the selection state yourself. Then you regain control over its colors.
Use the source, Luke!
Re: wxListCtrl & OnGetItemColumnAttr() & the selected row
What platform?
Using the code from here on MSW, the custom text colour in the Value column seems to stick, regardless of item selection.
I think that the selection rectangle is drawn over the items in all columns and hence the item background is ignored.
Using the code from here on MSW, the custom text colour in the Value column seems to stick, regardless of item selection.
I think that the selection rectangle is drawn over the items in all columns and hence the item background is ignored.
Re: wxListCtrl & OnGetItemColumnAttr() & the selected row
PB: That is the post I got my method from, however when hovering over a row the item colors on the hovered row revert to the default colors, not the color's I am setting.
My current work around is to override the OnSelection() handler and remove the selection from the wxListCtrl while remembering what that selection was, as well as use a MouseEvent (EVT_MOUSE_EVENTS) to intercept all mouse events over the wxListCtrl, only allowing left-clicks through (so the onSelection() handler gets called.) Plus use of the OnGetItemColumnAttr() as shown on your linked forum post.
This works, but is clunky.
In order to make these custom colors continually appear I've had to intercept the arrow keys as well and provide my own logic for moving the current selection up/down with an arrow key press, as well as calling RefreshItems() on the previous and current selections to get them to render with correct colors. It works, but is clunkier still - and it appears possible to hang the app with these key interceptions. Trying to figure out how to prevent that at the moment.
My current work around is to override the OnSelection() handler and remove the selection from the wxListCtrl while remembering what that selection was, as well as use a MouseEvent (EVT_MOUSE_EVENTS) to intercept all mouse events over the wxListCtrl, only allowing left-clicks through (so the onSelection() handler gets called.) Plus use of the OnGetItemColumnAttr() as shown on your linked forum post.
This works, but is clunky.
In order to make these custom colors continually appear I've had to intercept the arrow keys as well and provide my own logic for moving the current selection up/down with an arrow key press, as well as calling RefreshItems() on the previous and current selections to get them to render with correct colors. It works, but is clunkier still - and it appears possible to hang the app with these key interceptions. Trying to figure out how to prevent that at the moment.
- doublemax@work
- Super wx Problem Solver
- Posts: 474
- Joined: Wed Jul 29, 2020 6:06 pm
- Location: NRW, Germany
Re: wxListCtrl & OnGetItemColumnAttr() & the selected row
Another option could be to use wxGenericListCtrl. Unfortunately it doesn support OnGetItemColumnAttr(), but it shouldn't be too hard to add it.