Click here to Skip to main content
Click here to Skip to main content

CTreeComboBox: A Multiline Tree Combo Box that supports XML

, 25 Aug 2004
Rate this:
Please Sign up or sign in to vote.
This class implements a combo box that reads its data from an XML file, displays a tree as a drop down window, and supports mulitple selections.

Sample Image


This articles presents the CTreeComboBox which should actually have been called CIconMultilineXmlTreeComboBox.

It's a CButton derived class with two major features:

  • XML file support: The control displays a tree control as a drop down window. The tree control loads its data from XML files!
  • Multiline edit box: The edit box of the combo box can have the 'multiline' style so that it can support the selection of many items from the tree!

Other features include:

  • sorting of items for the multiline version.
  • icon support for both the tree control and the singe-line version of the control.

Using the code

Put an owner draw button in a dialog (i.e., IDC_MYCOMBO).

Declare a member variable for the control.

 CTreeComboBox m_mycombo;

Assign it to the button (in the DoDataExchange method of your dialog).

DDX_Control(pDX, IDC_MYCOMBO, m_mycombo);

Load an XML file:


or even better, load an XML file and a bitmap that contains the image list for the tree.


That's it! If you want to get the data you selected, declare a CString variable:

 CString m_text;

and assign it to the control (in the DoDataExchange method of your dialog).

 DDX_Text(pDX, IDC_MYCOMBO, m_text);


If the height of the button is larger than 32, the combo box will become automatically multiline, otherwise it will be a normal single line combo box.

The first icon of the bitmap that behaves as an imagelist is used by the class as the folder icon. The second icon is for the expanded folders. The third is for the leaves of the tree. The icons of the leaves are also displayed in the edit box in the single line version of the control.

The multiline version of the control supports alphabetical sorting of the selected items. You can enable or disable this feature using the method EnableSort(BOOL).


The tree support was based on the tree-based combo boxes by Dennis Howard and Hai Ha.

The code for XML document handling has been written by Pablo van der Meer.


5 August 2004: first version.


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

John Melas
Web Developer
Greece Greece
I've studied Electrical and Computer Engineer in
National Technical University of Athens.
I work as a software engineer since 1998.

Comments and Discussions

QuestionShould have Unicode support PinmemberMattias G3-Dec-12 23:56 
QuestionAdded TVN_SELCHANGED msg PinmemberMember 912173927-Jul-12 14:05 
QuestionAdd AbsoluteChildrenSelectableOnly support Pinmemberxiangzhai20-Nov-11 20:20 
QuestionHigh CPU load PinmemberChristian Stelter27-Feb-07 11:21 
AnswerRe: High CPU load PinmemberJohn Melas5-Mar-07 0:29 
QuestionMore problems PinmemberMarkBishop8-Aug-06 14:08 
AnswerRe: More problems PinmemberJohn Melas31-Aug-06 0:48 
GeneralNot compiling under VC7 Pinmembermile12346-Sep-04 23:17 
GeneralRe: Not compiling under VC7 PinmemberJohn Melas31-Aug-06 3:53 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150301.1 | Last Updated 26 Aug 2004
Article Copyright 2004 by John Melas
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid