views:

911

answers:

2

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

  1. Are there examples I missed?
  2. 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.

A: 

Is http://blog.csdn.net/yjqpro/archive/2008/10/24/3135880.aspx&ei=6c6WSdKjJIG86gP5uez4CA&sa=X&oi=translate&resnum=3&ct=result&prev=/search%3Fq%3DCHeaderCtrl%2Bwith%2Bfiltering%2Bfeature%26hl%3Den%26sa%3DN">this you are looking for?

Since it is in other language, I have given the googled address. Refer second result.

Vinay
A: 

My Google-fu confirms yours, no examples that add non-invasive filter interface to CListCtrl, with or without the CHeaderCtrl.

Simple approach
In your HDN_ITEMCLICK handler, check the ((NMHEADER)lParam).iButton. For iButton == 1, that's the right mouse button. Here's your chance to show a little CWnd-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 CListCtrl at the NM_RCLICK level so you get coordinate info (example.) Do some geometry to figure out if the click was on your filter icon, if so, show a little CWnd-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.

Aidan Ryan