Click here to Skip to main content
11,933,854 members (56,263 online)
Click here to Skip to main content
Add your own
alternative version


192 bookmarked

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

You may also be interested in...

Comments and Discussions

QuestionHow to add horizontal scroll bar in your control??? Pin
seawind5-Aug-02 22:06
memberseawind5-Aug-02 22:06 
Questionrelease version paint problem? Pin
Anonymous28-Jul-02 21:34
sussAnonymous28-Jul-02 21:34 
AnswerRe: release version paint problem? Pin
Anonymous30-Jul-02 23:11
sussAnonymous30-Jul-02 23:11 
GeneralRe: release version paint problem? Pin
goldsam22-Jul-05 21:48
membergoldsam22-Jul-05 21:48 
GeneralIcons instead of +/- Rectangles Pin
Dibi18-Jul-02 10:17
memberDibi18-Jul-02 10:17 
GeneralEnable/Disable a TreeItem Pin
foxi7714-Jul-02 23:40
memberfoxi7714-Jul-02 23:40 
QuestionBug in editable field ? Pin
Anonymous10-Jul-02 3:34
sussAnonymous10-Jul-02 3:34 
AnswerRe: Bug in editable field ? Pin
AlexP9681-Aug-04 14:54
memberAlexP9681-Aug-04 14:54 
QuestionWhy could it not work in the release mode? Pin
Zazu5-Jul-02 0:56
memberZazu5-Jul-02 0:56 
AnswerRe: Why could it not work in the release mode? Pin
Anonymous8-Jul-02 19:38
memberAnonymous8-Jul-02 19:38 
GeneralHelp request on compiling Pin
MightyThor3-Jul-02 2:58
memberMightyThor3-Jul-02 2:58 
GeneralRe: Help request on compiling Pin
MightyThor4-Jul-02 11:16
memberMightyThor4-Jul-02 11:16 
QuestionGood job!!! How about In-Place ToolTip? Pin
Anonymous11-Jun-02 21:20
memberAnonymous11-Jun-02 21:20 
GeneralBug Pin
Chris982029-May-02 1:32
memberChris982029-May-02 1:32 

the control is really nice, i use it extensively in my application.

i found one bug: if the user clicks on an edit item that isn't completely visible, then the edit field will be displayed on the control's bottom, but the tree will scroll up too far. therefore, sometimes it looks like just the succeeding item is being edited.

best regards,

GeneralCould we underline Items in tree controls Pin
bigZidane15-May-02 21:47
memberbigZidane15-May-02 21:47 
GeneralEasy way to edit root node Pin
Robert Vista13-May-02 8:39
memberRobert Vista13-May-02 8:39 
GeneralTabbing Pin
Anonymous9-May-02 5:15
memberAnonymous9-May-02 5:15 
GeneralMinor bug fix Pin
soichi28-Mar-02 12:57
membersoichi28-Mar-02 12:57 
GeneralRe: Minor bug fix Pin
AlexP9681-Aug-04 14:58
memberAlexP9681-Aug-04 14:58 
GeneralTrouble deleting items Pin
gbowers26-Feb-02 8:35
membergbowers26-Feb-02 8:35 
GeneralRe: Trouble deleting items Pin
Anonymous19-May-02 21:01
memberAnonymous19-May-02 21:01 
GeneralGood one, thanks! Pin
Anonymous26-Aug-02 18:28
sussAnonymous26-Aug-02 18:28 
GeneralRe: Trouble deleting items Pin
Alweit13-Dec-02 4:43
memberAlweit13-Dec-02 4:43 
GeneralFailed to create object (?) Pin
X. van Tilburg15-Feb-02 4:33
memberX. van Tilburg15-Feb-02 4:33 
GeneralRe: Failed to create object (?) Pin
X. van Tilburg19-Feb-02 6:22
memberX. van Tilburg19-Feb-02 6:22 
GeneralBug on color depth change Pin
dewey10-Feb-02 15:58
memberdewey10-Feb-02 15:58 
Generala common BUG Pin
Nick Avrionov30-Jan-02 15:52
memberNick Avrionov30-Jan-02 15:52 
GeneralRe: a common BUG Pin
sramsay30-Jan-02 16:20
membersramsay30-Jan-02 16:20 
GeneralStatic version Pin
Patrik Müller30-Jan-02 1:01
memberPatrik Müller30-Jan-02 1:01 
GeneralRe: Static version Pin
sramsay30-Jan-02 16:26
membersramsay30-Jan-02 16:26 
GeneralRe: Static version Pin
Patrik Müller30-Jan-02 19:49
memberPatrik Müller30-Jan-02 19:49 
GeneralSuggestion Pin
JurgenThor22-Jan-02 0:00
memberJurgenThor22-Jan-02 0:00 
GeneralRe: Suggestion Pin
sramsay22-Jan-02 6:30
membersramsay22-Jan-02 6:30 
GeneralRe: Suggestion Pin
JurgenThor23-Jan-02 12:34
memberJurgenThor23-Jan-02 12:34 
GeneralAnother properties control Pin
Andreane14-Jan-02 4:54
memberAndreane14-Jan-02 4:54 
GeneralReally Cool (and one criticism) Pin
Joel Holdsworth8-Jan-02 10:58
memberJoel Holdsworth8-Jan-02 10:58 
GeneralRe: Really Cool (and one criticism) Pin
sramsay12-Jan-02 16:53
membersramsay12-Jan-02 16:53 
GeneralBeautiful!! Pin
Lance8-Jan-02 2:06
memberLance8-Jan-02 2:06 
GeneralGood control Pin
Rob Riebau4-Jan-02 8:23
memberRob Riebau4-Jan-02 8:23 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.151126.1 | Last Updated 2 Jan 2002
Article Copyright 2002 by sramsay
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid