Example of the new ListView FilterBar feature (IE5)
Environment: Visual C++ 6, IE 5
This example program and code show you one of the ways to use the new, mostly undocumented, FilterBar feature of the ListView control that is available with IE5.0 (or greater). While the example application works, it is by no means an optimal example of how to use this new feature(!).
The Example Application will most likely better explain how to use the
FilterBar feature, as the important code is, IMHO, very well commented.
Please look it over first if you have any questions. (Tip: Set
your Tab size to 4!)
With IE5.0 comes a new feature for the ListView Control: the FilterBar. An example of how to use this new feature is in the example application (see above). For more information browse through your CommCtrl.h file. (Actually, this is a very smart thing to do each time you install a new version of the SDK! You might be suprised what you can find! This FilterBar stuff is one example, there is also a new Rebar style! Check it out for yourself!)
Using this new feature is simple. First, apply the HDS_FILTERBAR style to the ListView control's Header control. This tells the ListView's Header control to show the FilterBar (filter controls):
m_lcList.GetHeaderCtrl() -> ModifyStyle( 0, HDS_FILTERBAR ); // Add The FilterBar StyleThen, specify the Filter Types for the Columns. In the following example code, I set the Filter Type to HDFT_ISSTRING, which is the String filter type:
HDITEM hdItem; hdItem.mask = ( HDI_FILTER ); // Set Mask For Filter Type Information hdItem.type = HDFT_ISSTRING; // Set String Filter Type pHeader -> SetItem( 0, &hdItem ); // Set Item Information pHeader -> SetItem( 1, &hdItem ); // Set Item Information pHeader -> SetItem( 2, &hdItem ); // Set Item InformationNow, use the HDM_SETFILTERCHANGETIMEOUT message to set the Timeout value for Filter Change notifications. This allows the user to type in a value without the application constantly processing Filter Change notifications. On the other hand, if you want to get a notification for each character, you could try setting the Timeout value to a very small number. This is useful for incremental filtering.
m_lcList.GetHeaderCtrl() -> SendMessage( HDM_SETFILTERCHANGETIMEOUT, 0, 1000 ); // Set One Second Timeout (Milliseconds)All that is left to do is to process the notification messages sent by the FilterBar. These notification messages are:
HDN_FILTERCHANGE Sent to notify you of changes to the Filter HDN_FILTERBTNCLICK Sent to notify you of the FilterBar button being pressedSee the CommCtrl.h file for more information on the above notification messages, and the structures they use.
To get filter information from the control, you use the HDITEM structure, which now has two additional data members, type and pvFilter. Set the mask member of the HDITEM structure with the HDI_FILTER value to manipulate the FilterBar specific members. The type member is used to specify the Filter type, and can accept the following values:
HDFT_ISSTRING Filter type is String HDFT_ISNUMBER Filter type is Number (int) HDFT_HASNOVALUE Filter is Empty (Setting this value will clear the existing Filter)The pvFilter member is used to obtain the value in the filter. If type is set to HDFT_ISNUMBER, pvFilter should point to an int. If type is set to HDFT_ISSTRING, pvFilter is a pointer to an HDTEXTFILTER structure, which itself contains a pointer to a buffer, and the (character) length of the buffer. (Note that I could not get the Number type to work correctly.)
After calling CHeaderCtrl::GetItem(...), the pvFilter (int or HDTEXTFILTER structure pointer) should be populated with the Filter data. What you do with this data is up to you.
In the Example Application, this filter data is used to perform incremental filtering of the set of data, and then the resulting data set, if any, is displayed.
While I am no expert with the FilterBar stuff, I would be more than happy to try to answer any questions about it. Have fun!
Downloads
Download demo application - 40 KbDownload demo project - 8 Kb
Download source - 16 Kb

Comments
HDM_GETITEMW leaks memory with HDI_FILTER
Posted by itsomne on 04/13/2009 03:46amIt is not working on my system
Posted by bharatsingh on 03/16/2005 12:26ami downloaded this demo project, it is working on my system very well, but when i wrote my own code like this then there are so many errors like HDS_FILTERBAR , HDI_FILTER and hdItem.type = HDFT_ISSTRING not define. there are many other errors like this please helpe my email id is bharat.singh@sisl.co.in
-
ReplyMissing SDK...
Posted by jtwine on 02/03/2006 01:40pmYou need to have the updated SDK installed correctly to have those values available. -=- James
ReplyFilter edit don't get input more that 4 chars if text set programetically?
Posted by Legacy on 08/09/2002 12:00amOriginally posted by: Sajid Majid
Hi All,
On button click I am creating ListBox & then selecting value to filter. The selected value is set in filter using SetItem(...). This is ok, I can delete some chars from set value but can't enter if more than 4 char in edit. I have found this problem when I have set value for column from list, otherwise u can edit with keyboard without any problem.
Hope any one have any solution?.
Regards.
ReplyMajid.
Access Violation in Comctl32.dll
Posted by Legacy on 02/19/2002 12:00amOriginally posted by: Kyle Sluder
When my program calls pHeader->SetItem() I get an Access Violation in Comctl32.dll... is something going on with SetItem? I'm running VC++ 6 Standard, Win98 SE, IE6, and Office 2000 Pro.
Also, how do I filter the list? In your demo app (which works without an access violation) I enter a filter into the FilterBar (example: Car) and click on the filter icon, but it doesn't want to work... I still get all the Bucket items, for example.
ReplyBetter way...
Posted by Legacy on 12/06/2001 12:00amOriginally posted by: Stephan Roth
ReplyRE:The program can not compile!
Posted by Legacy on 11/28/2001 12:00amOriginally posted by: XingJun Zhang
Thanks Mr James for this free code program.But downloaded the program and cannot get it to compile: 26 errors.
1 - FBListCtrl.cpp(28) : error C2065: 'HDN_FILTERCHANGE' : undeclared identifier
2 - FBListCtrl.cpp(29) : error C2065: 'HDN_FILTERBTNCLICK' : undeclared identifier
etc...
I have downloaded the latesd SDK and installed it, also I have added the include and lib directory of SDK into the IDE of VC6.
ReplyThanks!
Any way to tab b/w filters?
Posted by Legacy on 06/29/2001 12:00amOriginally posted by: Keri
Has anybody discovered a way to allow the user to move b/w filter edits w/o using the mouse? I'd love to get the TAB key to do the trick...
ReplyCode does not compile
Posted by Legacy on 05/03/2001 12:00amOriginally posted by: Bill Roach
ReplyRefresh problem when double-clicking a column intersection...
Posted by Legacy on 10/13/2000 12:00amOriginally posted by: Benjamin Mayrargue
There is a refresh problem when you double-click a column intersection in the column header in order to make it resize to its content.
The column extends to the width of its largest item.
But the filter button is not erased from its previous position.
This is in "comctl32.dll" ver 5.81.4134.600
(product ver 5.50.4134.600)
from IE 5.5 / NT4
___________________________
Replyhttp://welcome.to/softbird
Anyone that is having problems...
Posted by Legacy on 09/22/2000 12:00amOriginally posted by: James R. Twine
Please LMK exactly what version of Windows, IE, and MS Office is installed on your system. I am going to try to find time to find out why this thing is getting wonky on certain systems.
-=- James.
ReplyLoading, Please Wait ...