wxListCtrl & OnGetItemColumnAttr() & the selected row Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
User avatar
bsenftner
Experienced Solver
Experienced Solver
Posts: 85
Joined: Thu May 26, 2016 9:19 pm

wxListCtrl & OnGetItemColumnAttr() & the selected row

Post by bsenftner »

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...
User avatar
doublemax
Moderator
Moderator
Posts: 19115
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxListCtrl & OnGetItemColumnAttr() & the selected row

Post by doublemax »

AFAIK the "selected" colors can't be overriden.
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?
They're all in the documentation and there aren't any hidden ones.

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!
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxListCtrl & OnGetItemColumnAttr() & the selected row

Post by PB »

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.
User avatar
bsenftner
Experienced Solver
Experienced Solver
Posts: 85
Joined: Thu May 26, 2016 9:19 pm

Re: wxListCtrl & OnGetItemColumnAttr() & the selected row

Post by bsenftner »

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.
User avatar
doublemax@work
Super wx Problem Solver
Super wx Problem Solver
Posts: 474
Joined: Wed Jul 29, 2020 6:06 pm
Location: NRW, Germany

Re: wxListCtrl & OnGetItemColumnAttr() & the selected row

Post by doublemax@work »

Another option could be to use wxGenericListCtrl. Unfortunately it doesn support OnGetItemColumnAttr(), but it shouldn't be too hard to add it.
Post Reply