Click here to Skip to main content
11,412,526 members (72,249 online)
Click here to Skip to main content

CPropTree v1.0 - Property Tree Control

, 1 Jan 2002
Rate this:
Please Sign up or sign in to vote.
Custom MFC tree control that support dynamic editable items

Sample Image Sample Image Sample Image


The CPropTree class implements a tree control that is similar to the property view seen in Visual Studio .Net. The source project compiles to a DLL so you can easily incorporate it into your project. You can check my web page for more information on the control.

The control has two window areas:

  • Tree Control
  • Descriptive area

The tree control section functions just a like a normal tree control with an addition of a splitter bar separating the tree item properties. Tree item properties are inherited from the CPropTreeItem class. These items can be edit controls, static text, dropdown combo list, or any type of control you wish to create. Items on the root level of the tree control do not have editable properties. They are used as section headers.

Tree items can contain checkboxes. By default properties that are editable (non-readonly), are displayed in bold lettering. Read only or non-editable items are displayed in a normal font.

The descriptive area displays the selected item's text and any informational text. This section can be displayed or hidden by calling CPropTree::ShowInfoText().


To use the control, create an instance of the class in your dialog or view class header. In the OnInitDialog() or OnCreate() initialize the control:

DWORD dwStyle;
CRect rc;

// PTS_NOTIFY - CPropTree will send notification messages to the parent window

// Init the control's size to cover the entire client area

// Create CPropTree control
m_Tree.Create(dwStyle, rc, this, IDC_PROPERTYTREE);

To add items to the control, dynamically create objects inherited by the CPropTreeItem class and call the CPropTree::InsertItem() method.

CPropTreeItem* pItem1;

pItem1 = m_Tree.InsertItem(new CPropTreeItem());
pItem1->SetInfoText(_T("This is a root level item"));

CPropTreeItem* pItem2;

pItem2 = m_Tree.InsertItem(new CPropTreeItemEdit(), pItem1);
pItem2->SetInfoText(_T("This is a child item of Properties, with an edit control"));

pItem2->SetItemValue((LPARAM)_T("This is some default text for the edit control"));

Advanced Features

Notification Messages

The control uses WM_NOTIFY notification messages to signal events. Add a ON_NOTIFY message handler to the parent window to process notifications. The control supports most of the common NM_ codes with addition of the following CPropTree specific WM_NOTIFY codes.

  • PTN_INSERTITEM when an item is inserted
  • PTN_DELETEITEM when an item is about to be deleted
  • PTN_DELETEALLITEMS when a call is made to delete all items
  • PTN_ITEMCHANGED when an item's property has been modified
  • PTN_SELCHANGE when the current selection changed
  • PTN_ITEMEXPANDING when an item is about to expand or close
  • PTN_COLUMNCLICK when the mouse clicks on the splitter bar
  • PTN_PROPCLICK when the mouse clicks on an item's property area
  • PTN_CHECKCLICK when the mouse clicks on an item's checkbox

PTN_ notification messages returns the NMPROPTREE structure. You can use this structure along with the CPropTreeItem::SetCtrlID() method to determine the tree item that sent an event.


void CMyDialog::OnItemChanged(NMHDR* pNotifyStruct, LRESULT* plResult)

	if (pNMPropTree->pItem)
		// retrieve pItem's changed data

	*plResult = 0;

Custom Property Items

The library already has some default derived CPropTreeItem classes ready to use. Such as an edit control CPropTreeItemEdit, color picker CPropTreeItemColor, dropdown combobox CPropTreeItemCombo and static text CPropTreeItemStatic. To create your own custom property items:

  • Create your own class inherited by CPropTreeItem. This class usually will have multiple inheritance depending on what type of item you want to create.
    class CMyCustomEditPropItem : public CEdit, public CPropTreeItem
    	virtual ~CMyCustomEditPropItem();
    class CMyCustomComboBoxPropItem : public CComboBox, public CPropTreeItem
    	virtual ~CMyCustomComboBoxPropItem();
  • Override the CPropTreeItem virtual methods to implement your property item.
  • Dynamically create an instance of your class and insert it into a CPropTree control.

The methods most often overriden from CPropTreeItem are:

  • CPropTreeItem::OnActivate(). Called when the property area is clicked by the mouse or the enter key has been pressed on the selected item. The OnActivate() method is where you show the property item's window if it has one (such as an edit control or a popup menu).
  • CPropTreeItem::OnCommit(). Called when data has been commited. In this method you would extract the changed data and hide the property's item's window. OnCommit() gets called when CommitChanges() is called. A derived CPropTreeItem class would call CommitChanges() during a loss of the input focus or if the "Enter" key is press as in a edit control.
  • CPropTreeItem::DrawAttribute(). CPropTree calls DrawAttribute() when the property item needs to be displayed. Drawing is done directly on the display context of the PropTree control.


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


United States United States
No Biography provided

Comments and Discussions

QuestionHow can it support VS2008, It can't Draw Text in VS2008.Thanks! Pin
mconstor at 3-May-10 22:55
membermconstor3-May-10 22:55 
AnswerRe: How can it support VS2008, It can't Draw Text in VS2008.Thanks! Pin
windsky110 at 30-Mar-11 16:51
memberwindsky11030-Mar-11 16:51 
GeneralLicense Pin
silent_neiep at 1-Dec-09 16:34
membersilent_neiep1-Dec-09 16:34 
Generalcolor select dialog bug Pin
yq_sun at 25-Jun-09 19:41
memberyq_sun25-Jun-09 19:41 
GeneralFind a bug work with sizecontrolbar [modified] Pin
m_harriss at 7-May-09 12:10
memberm_harriss7-May-09 12:10 
GeneralMemory leaks found and fixed [modified] Pin
Shashidhar Kamath at 23-Oct-08 13:42
memberShashidhar Kamath23-Oct-08 13:42 
GeneralControl on the dialog box with other controls Pin
Shashidhar Kamath at 23-Oct-08 9:44
memberShashidhar Kamath23-Oct-08 9:44 
GeneralCheckbox is on wrong side Pin
johnnyk4277 at 28-Jun-08 23:23
memberjohnnyk427728-Jun-08 23:23 
GeneralImplementing tab key Pin
Ionut Codrut at 19-Nov-07 9:17
memberIonut Codrut19-Nov-07 9:17 
GeneralDebug assertion error [modified] Pin
Ionut Codrut at 19-Nov-07 8:32
memberIonut Codrut19-Nov-07 8:32 
GeneralRe: Debug assertion error Pin
rivan83 at 8-Feb-08 0:31
memberrivan838-Feb-08 0:31 
GeneralRe: Debug assertion error Pin
heqj06183 at 8-Oct-09 4:38
memberheqj061838-Oct-09 4:38 
GeneralI am in china.My English is poor,but I need you help urgently. Pin
Plainzeng at 29-Mar-07 17:11
memberPlainzeng29-Mar-07 17:11 
GeneralLanguages and combos questions Pin
andrewtruckle at 24-Mar-07 8:51
memberandrewtruckle24-Mar-07 8:51 
Question64-bit? Pin
Traal at 18-Oct-06 12:37
memberTraal18-Oct-06 12:37 
AnswerRe: 64-bit? Pin
Mohammed Hossny at 18-May-09 16:12
memberMohammed Hossny18-May-09 16:12 
GeneralBug Hiding Info Text Pin
Merlin Avery at 21-Mar-06 12:55
memberMerlin Avery21-Mar-06 12:55 
QuestionHello,sramsay,can you help me? Pin
oldmonster at 11-Jun-05 18:12
memberoldmonster11-Jun-05 18:12 
QuestionIf there is a special Tree with root node on right side? Pin
Wang Jian-gong at 8-Jun-05 22:49
memberWang Jian-gong8-Jun-05 22:49 
QuestionExtending CPropTree? Pin
Anonymous at 30-Apr-05 15:52
sussAnonymous30-Apr-05 15:52 
Questionhow to delete the root level items Pin
itsh11 at 11-Apr-05 12:36
memberitsh1111-Apr-05 12:36 
Generalcolumn resizing Pin
Popyweb at 28-Jan-05 15:45
memberPopyweb28-Jan-05 15:45 
GeneralShow Tree Lines Pin
Manoj Singh K at 18-Jan-05 19:54
memberManoj Singh K18-Jan-05 19:54 
QuestionHelp! How to set the width for each item ??? Pin
brapler at 15-Jan-05 0:16
memberbrapler15-Jan-05 0:16 
QuestionHow to us the dll in a new project Pin
d00_ape at 25-Dec-04 10:44
memberd00_ape25-Dec-04 10:44 
Generalresizing issue Pin
sammyc at 21-Dec-04 15:56
membersammyc21-Dec-04 15:56 
Question[newbie] What to do with edited data? Pin
stefkeB at 7-Sep-04 0:48
memberstefkeB7-Sep-04 0:48 
Questionhow can add a new column? Pin
jerry li at 2-Jun-04 17:11
memberjerry li2-Jun-04 17:11 
QuestionWhere's the source????? Pin
Brad Bruce at 7-May-04 4:27
memberBrad Bruce7-May-04 4:27 
AnswerRe: Where's the source????? Pin
andrewtruckle at 24-Mar-07 8:53
memberandrewtruckle24-Mar-07 8:53 
QuestionControls with no borders ? Pin
Gilles Diawara at 1-Apr-04 8:49
memberGilles Diawara1-Apr-04 8:49 
GeneralBug in descriptive area. Pin
WilliamGS at 25-Mar-04 7:24
memberWilliamGS25-Mar-04 7:24 
GeneralScrollbar stops drawing itself Pin
Zuka at 15-Jan-04 13:23
memberZuka15-Jan-04 13:23 
GeneralRe: Scrollbar stops drawing itself Pin
MHillary at 14-Jul-04 3:08
memberMHillary14-Jul-04 3:08 
GeneralProblems adding CPropTree to my project Pin
IGx89 at 4-Dec-03 15:40
memberIGx894-Dec-03 15:40 
Questionhow to add columns ? Pin
Broken-Sword at 9-Nov-03 20:22
memberBroken-Sword9-Nov-03 20:22 
GeneralUsing in Visual Basic Pin
ledi at 21-Aug-03 4:27
memberledi21-Aug-03 4:27 
QuestionCheckboxes? Pin
ihaml at 28-Jul-03 6:54
memberihaml28-Jul-03 6:54 
Generalexcellent!but... Pin
Pole at 15-Jun-03 21:24
memberPole15-Jun-03 21:24 
QuestionHow to add this control in a window? Pin
tasos milix at 11-Mar-03 23:40
membertasos milix11-Mar-03 23:40 
AnswerRe: How to add this control in a window? Pin
Devil for ever at 22-Feb-06 7:07
memberDevil for ever22-Feb-06 7:07 
Generalall control get hidden Pin
New2 at 27-Jan-03 3:17
sussNew227-Jan-03 3:17 
GeneralException OnSetCursor Pin
Anonymous at 11-Nov-02 15:38
sussAnonymous11-Nov-02 15:38 
Generalclearing items Pin
Anonymous at 11-Nov-02 3:35
sussAnonymous11-Nov-02 3:35 
GeneralRe: clearing items Pin
Alweit at 13-Dec-02 4:33
memberAlweit13-Dec-02 4:33 
GeneralRe: clearing items Pin
sdepasquale at 29-Oct-04 4:44
membersdepasquale29-Oct-04 4:44 
GeneralRe: clearing items Pin
alex k at 20-Apr-05 11:03
memberalex k20-Apr-05 11:03 
GeneralRe: clearing items Pin
Ronaldo in Chinese at 3-Feb-06 2:13
memberRonaldo in Chinese3-Feb-06 2:13 
GeneralRe: clearing items Pin
Ronaldo in Chinese at 3-Feb-06 2:15
memberRonaldo in Chinese3-Feb-06 2:15 
GeneralRe: clearing items Pin
Ronaldo in Chinese at 3-Feb-06 2:16
memberRonaldo in Chinese3-Feb-06 2:16 

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
Web04 | 2.8.150427.1 | Last Updated 2 Jan 2002
Article Copyright 2002 by sramsay
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid