Property Listbox | CodeGuru

Property Listbox

Environment: Visual C++ 6 SP4 About This article describes a Property List Box. This kind of list box is used by several IDE’s such as VB to set properties for controls. I wrote this originally for a custom Java IDE that I have been developing. Like the property boxes used by apps. like VB, the […]

Written By
CodeGuru Staff
CodeGuru Staff
Jun 12, 2000
2 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

Environment: Visual C++ 6 SP4

About

This article describes a Property List Box. This kind of list box is used by several IDE’s such as VB to set properties for controls. I wrote this originally for a custom Java IDE that I have been developing. Like the property boxes used by apps. like VB, the control (such as a combo box) that is associated with a property is only displayed when the user click on the property’s row.

With the list box you can specify each property row to contain either an edit box, a combo box, an RBG color value, a font name, or a file name. When the user wants to specify a color, font, or file name, the appropriate common dialog is displayed.

The property list box even allows the user to resize the columns!

Adding a CPropertyList box to a dialog

  1. Add the files ProperyList.h and PropertyList.cpp to your project.
  2. Add a list box to the dialog in which you wish to place a property list box.
  3. Set the properties for the list box to:
    • Selection: Single
    • Owner Draw: Variable
    • Check the ‘Has Strings’ box and Uncheck the ‘Sort’ box
  4. Using the ClassWizard add a CPropertyList member variable for the list box. If you don’t see a choice called CPropertyList, then select CListBox instead, and then manually edit the dialog class and set the variable to type CPropertyList.
  5. Include the file “PropertyList.h” in your dialog class.

Using the CPropertyList box

  1. Create an object of type CPropertyItem. The constructor syntax is as follows:
    CPropertyItem(CString propName, CString curValue,
                  int nItemType, CString cmbItems)
    

    where

    • propName is a name for the property and is displayed in the first column
    • curValue is the initial value for the property
    • nItemType is either
      • PIT_COMBO (combo box control)
      • PIT_EDIT (edit box control)
      • PIT_COLOR (color chooser)
      • PIT_FONT (font selector)
      • PIT_FILE (file chooser)
    • cmbItems are the combo items if nItemType is set to PIT_COMBO, e.g., “TRUE|FALSE|”.
  2. Add the CPropertyItem object to the CPropertyList box using the AddPropItem method:
    int AddPropItem(CPropertyItem* pItem);
    
Advertisement

Examples:

The following lines add a property of each type to a CPropertyList box (m_propList).

//Add an edit box for a property called 'ToolTip Text'
CPropertyItem* propItem1 =
 new CPropertyItem("ToolTip Text","",PIT_EDIT,"");
m_propList.AddPropItem(propItem1);

//Add a combo box with the choices 'true' and 'false'
//for a property called 'Enabled'
CPropertyItem* propItem2 =
 new CPropertyItem("Enabled","true",PIT_COMBO,"true|false|");
m_propList.AddPropItem(propItem2);

//Add a color chooser for a property called 'Back. Color'
CPropertyItem* propItem3 =
 new CPropertyItem("Back. Color","",PIT_COLOR,"");
m_propList.AddPropItem(propItem3);

//Add a file chooser for a property called 'File Name'
CPropertyItem* propItem4 =
 new CPropertyItem("File Name","",PIT_FILE,"");
m_propList.AddPropItem(propItem4);

//Add a font chooser for a property called 'Font'
CPropertyItem* propItem5 = new CPropertyItem("Font","",PIT_FONT,"");
m_propList.AddPropItem(propItem5);

That’s it. Download the project file to see a working example. The source for the CPropertyList class contains additional documentation pertaining to the code.

Downloads

Download demo project – 25 Kb

Download source – 5 Kb

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.