Click here to Skip to main content
14,031,266 members
Click here to Skip to main content
Add your own
alternative version


57 bookmarked
Posted 23 Feb 2003

A Checkbox Tree Control for Use in Filtering Selections

Rate this:
Please Sign up or sign in to vote.
An ATL filter control

Sample Image - maximum width is 600 pixels


A year ago, I posted an MFC control in the article "An Enhanced CCheckComboBox". Many readers asked me to make this control a COM component available from VB or .NET. Another request was to make the addition of new controls as quick as possible. I decided to create an ATL component which contains a collection of combos with checked trees dropdowns. The combos are created dynamically and displayed in 2, 3 or 4 columns.

Using the Code

To use this code, first you will have to build the "QuickFilter" project in VC++ 6.0 or VC++ .NET. Then, you can run the three demo projects: "Test with VB", "Test with HTML" and "Test with C#".

Example for populating the first combo: (C#)

//## INIT Countries
QF.set_CheckLabel( 0, "Countries:" );
QF.set_Field( 0, "Countries.ID" );
QF.AddFolder( 0, "North America" );
    QF.AddString( 0, "USA", 5, ROOT_LEVEL + 2 );
    QF.AddString( 0, "Canada", 6, ROOT_LEVEL + 2 );
QF.AddFolder( 0, "Europe" );
    QF.AddString( 0, "UK", 7, ROOT_LEVEL + 2 );
    QF.AddString( 0, "Germany", 8, ROOT_LEVEL + 2 );
    QF.AddString( 0, "Russia", 9, ROOT_LEVEL + 2 );
QF.AddFolder( 0, "Asia" );
    QF.AddString( 0, "Israel", 10, ROOT_LEVEL + 2 );
QF.CheckAll( 0, true );

Points of Interest

The ComboBox control is made from an EditBox, a Button and a TreeView. The TreeView is a child of the desktop window, and is shown or hidden when the user presses the button or the edit of the combo (this behavior is by design). I no longer subclass the parent window of the combo, as I did in the previous article but instead, I use mouse capture and the LostFocus event to hide the dropdown when needed.

When the user presses the button of the combo, I show the dropdown and I wait the WM_LBUTTONUP message to capture the mouse. At this point, I know that a click outside my control will have to hide the dropdown. Everything seems to be easy, but there is a problem: the scroll bars of the tree dropdown will not work properly if the mouse is already captured. To handle this situation, we will release the mouse capture just as long as the user uses the scrolls and then recapture the mouse again:

LRESULT CCheckTreeCtrl::OnLButtonDown(UINT uMsg, WPARAM wParam, 
                                           LPARAM lParam, BOOL& bHandled)
    //## RELEASE Capture
    if (hWnd == m_hWnd)
        if (GetCapture() == hWnd){
            LRESULT result = ::SendMessage( hWnd, WM_NCHITTEST, NULL, 
                                            MAKELONG(point.x, point.y));
            if ((result == HTVSCROLL) || (result == HTHSCROLL)){
                m_bScroll = TRUE;
                ::SendMessage( hWnd, WM_NCLBUTTONDOWN, result, 
                               MAKELONG(point.x, point.y));

When the user finishes using the scrollbars, a WM_CAPTURECHANGED message will be sent. This is where we will capture the mouse again.

LRESULT CCheckTreeCtrl::OnCaptureChanged(UINT uMsg, WPARAM wParam, 
                                              LPARAM lParam, BOOL& bHandled)
    //## SET Capture
    if (IsWindowVisible())
        if (lParam == NULL)
            if (m_bScroll){
                m_bScroll = FALSE;

The rest is quite straightforward. Enjoy using it!


This is the first release.


This article has no explicit license attached to it, but may contain usage terms in the article text or the download files themselves. If in doubt, please contact the author via the discussion board below.

A list of licenses authors might use can be found here.


About the Author

Magerusan Grigore Cosmin
Web Developer
Romania Romania
In June 2002 Magerusan Grigore Cosmin, took a Master's Degree in Computer Science at UBB University in Cluj.

He has ~2 years of experience using in VC++.

Comments and Discussions

QuestionHow I can use it in VS2010 C#? Pin
Sparehawk12-Jul-11 1:47
memberSparehawk12-Jul-11 1:47 
GeneralMy vote of 5 Pin
Global Analyser5-Nov-10 0:41
memberGlobal Analyser5-Nov-10 0:41 
QuestionCan someone help me fix this code? I get errors! Pin
David Mark Bell6-Sep-09 8:11
memberDavid Mark Bell6-Sep-09 8:11 
QuestionLanguage Related Pin
Member 22265221-May-09 11:52
memberMember 22265221-May-09 11:52 
QuestionCompiled solution ... ??? Pin
Nima Sharifat3-Sep-08 22:47
memberNima Sharifat3-Sep-08 22:47 
GeneralC# .NET 2.0 Pin
RodrigoAntunes17-Apr-07 10:48
memberRodrigoAntunes17-Apr-07 10:48 
QuestionMethods Pin
braveheartkenya27-Dec-05 6:42
memberbraveheartkenya27-Dec-05 6:42 
Generalneed the dll Pin
davemack5-Apr-04 5:39
memberdavemack5-Apr-04 5:39 
Generalright to left Pin
AHMAD COM14-Jan-04 19:15
memberAHMAD COM14-Jan-04 19:15 
GeneralQuestions Pin
SUPER_ZORRO13-May-03 22:21
memberSUPER_ZORRO13-May-03 22:21 
GeneralRe: Questions Pin
Magerusan Grigore Cosmin14-May-03 1:52
memberMagerusan Grigore Cosmin14-May-03 1:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web04 | 2.8.190419.4 | Last Updated 24 Feb 2003
Article Copyright 2003 by Magerusan Grigore Cosmin
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid