Background:
Applications that manipulate a collection of data typically present using a grid containing a header. These same applications typically incorporate a filter to allow the user to narrow the data set (Excel is a wonderful example. There are many others). In my MFC application, I’m attempting to do the same using the CListCtrl and CHeaderCtrl combination. This combination has already enabled my application to provide for multiple column sorting including using the Image capabilities of the individual header items to represent ascending/descending sort order.
I have used my best Google-fu to locate any examples where the CHeaderCtrl was extended/customized to include custom drawing to account for the addition of the filter button and display an associated drop menu for user input of filter criteria when clicked.
Question(s):
- Are there examples I missed?
- If no examples available via the internet, what approach(es) should I consider in customizing CListCtrl and CHeaderCtrl to accomplish my goal?
Additional Comments:
One of the answers referenced the built-in FilterBar functionality. Yes I’ve seen that but it’s not what I’m looking for. I’m looking to specifically emulate the non-static, non-visually intrusive filtering capabilities of Excel and other filter-enabled applications.
My Google-fu confirms yours, no examples that add non-invasive filter interface to
CListCtrl, with or without theCHeaderCtrl.Simple approach
In your
HDN_ITEMCLICKhandler, check the((NMHEADER)lParam).iButton. ForiButton == 1, that’s the right mouse button. Here’s your chance to show a littleCWnd-dervied filter UI. Problem with this approach is there’s no visual indication that right-click will bring up a filter menu.More complicated
Create three column header images – filter icon, up arrow + filter icon, down arrow + filter icon. When not sorted on a column, show the filter only image, otherwise use the appropriate arrow + filter image. Handle click on the
CListCtrlat theNM_RCLICKlevel so you get coordinate info (example.) Do some geometry to figure out if the click was on your filter icon, if so, show a littleCWnd-derived filter UI. You can get even fancier and show the current filter in header tooltips, create more images with colored filters to show when a filter is active.