Click here to Skip to main content
11,644,286 members (65,833 online)
Click here to Skip to main content

CTreeComboBox: A Multiline Tree Combo Box that supports XML

, 25 Aug 2004 73.1K 2.9K 43
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

Introduction

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:

 m_mycombo.LoadXml("countries.xml");

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

 m_mycombo.LoadXml("countries.xml",IDB_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);

Remarks

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

Credits

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.

History

5 August 2004: first version.

License

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

Share

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.

You may also be interested in...

Comments and Discussions

 
QuestionShould have Unicode support Pin
Mattias G3-Dec-12 22:56
memberMattias G3-Dec-12 22:56 
QuestionAdded TVN_SELCHANGED msg Pin
Member 912173927-Jul-12 13:05
memberMember 912173927-Jul-12 13:05 
QuestionAdd AbsoluteChildrenSelectableOnly support Pin
xiangzhai20-Nov-11 19:20
memberxiangzhai20-Nov-11 19:20 
QuestionHigh CPU load Pin
Christian Stelter27-Feb-07 10:21
memberChristian Stelter27-Feb-07 10:21 
AnswerRe: High CPU load Pin
John Melas4-Mar-07 23:29
memberJohn Melas4-Mar-07 23:29 
QuestionMore problems Pin
MarkBishop8-Aug-06 13:08
memberMarkBishop8-Aug-06 13:08 
AnswerRe: More problems Pin
John Melas30-Aug-06 23:48
memberJohn Melas30-Aug-06 23:48 
GeneralNot compiling under VC7 Pin
mile12346-Sep-04 22:17
membermile12346-Sep-04 22:17 
GeneralRe: Not compiling under VC7 Pin
John Melas31-Aug-06 2:53
memberJohn Melas31-Aug-06 2: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
Web02 | 2.8.150731.1 | Last Updated 26 Aug 2004
Article Copyright 2004 by John Melas
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid