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

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


Comments

  • Helluva good job!

    Posted by manudino on 06/02/2005 08:46am

    Excellent job with very few lines of code!

    Reply
  • help me!

    Posted by Legacy on 01/08/2004 12:00am

    Originally posted by: shanmukh

    pls i want these files code
    #define PIT_COMBO 0 //PIT = property item type
    #define PIT_EDIT 1
    #define PIT_COLOR 2
    #define PIT_FONT 3
    #define PIT_FILE 4

    #define IDC_PROPCMBBOX 712
    #define IDC_PROPEDITBOX 713
    #define IDC_PROPBTNCTRL 714
    thanking u,
    shanmukh

    Reply
  • How to get the data from editable cell

    Posted by Legacy on 05/13/2003 12:00am

    Originally posted by: Tim Guo


    Who can advicse me how to get the data from editable cell on this page, I wamt to use this property page as input window.


    Thanks very much

    Tim

    Reply
  • Bug found, and here is my solution.

    Posted by Legacy on 12/22/2002 12:00am

    Originally posted by: ruxming

    My program needs to use ResetContent() to remove all the items.
    
    But when PropertyList's (CButton)m_btnCtrl had already shown,
    and after ResetContent(),
    if the total items are less then before.
    then the button would still remain on the blank of the listBox!!

    so here is ruxming's modification.

    // public:
    void CPropertyList::CleanAll() ///[Modify]
    {
    if (m_btnCtrl)
    m_btnCtrl.ShowWindow(SW_HIDE);
    ResetContent();
    }
    // Then has to call CleanAll() instead of ResetContent();

    Any better solution?

    Reply
  • A few nice changes

    Posted by Legacy on 11/26/2002 12:00am

    Originally posted by: Philippe Dykmans

    Good work! This saved me a lot of time!
    
    

    Here are a few easy changes that make the control a bit
    nicer... in my opinion ;-)

    1) Show the dropdown list of a combobox immediately on
    selection. Allows for immediate selection after only one
    click, instead of two.

    (in propertylist.cpp)

    CPropertyList::OnSelchange()
    {
    ...
    if (pItem->m_nItemType==PIT_COMBO)
    {
    ...
    if (j != CB_ERR)
    m_cmbBox.SetCurSel(j);
    else
    m_cmbBox.SetCurSel(0);

    m_cmbBox.ShowDropDown(); // add this line
    }
    ...
    }

    2) Hide the combobox immediately after selection.

    (in propertylist.cpp)

    Change the line:
    ON_CBN_KILLFOCUS(IDC_PROPCMBBOX, OnKillfocusCmbBox)

    Into:
    ON_CBN_CLOSEUP(IDC_PROPCMBBOX, OnKillfocusCmbBox)

    3) Better creation of the combobox. The combobox should
    display a vertical scrollbar when its list contains a
    large number of items. And it may be a bit larger as well.
    Personally i don't like the CBS_NOINTEGRALHEIGHT style.
    But you can keep it if you want.

    (in propertylist.cpp)

    Change the lines:
    rect.bottom += 100;
    m_cmbBox.Create(CBS_DROPDOWNLIST | CBS_NOINTEGRALHEIGHT | WS_VISIBLE | WS_CHILD | WS_BORDER,

    Into:
    rect.bottom += 300;
    m_cmbBox.Create(CBS_DROPDOWNLIST | WS_VSCROLL | WS_VISIBLE | WS_CHILD | WS_BORDER,

    Happy coding!


    Reply
  • It can't be used in pocket PC environment

    Posted by Legacy on 10/23/2002 12:00am

    Originally posted by: Sky Sapphire

    When I used it (just showing text), it gives me a blank rect.

    Reply
  • How can I enable and disable items

    Posted by Legacy on 06/18/2002 12:00am

    Originally posted by: Thomas

    First of all, it's a very good work... i've saved a lot of time with this code.
    Could somebody tell me how i can enable and disable some items in a proplist?

    Reply
  • No OnKillFocus for ComboBox with DropDown Style

    Posted by Legacy on 05/23/2002 12:00am

    Originally posted by: Burkhard

    Hi,

    first thanks for you work. It helped me to implement my own PropertyControl.
    I've one problem with a CCombobox using DropDown Style (editable text). For this control the OnKillFocus will not be called as expected.
    I hide my controls on OnVScroll message. Before this the framework calls normlay OnKillFocus so I can read the changings. This works for CEdit and CComboBox with DropDownList Style, but not for DropDown Style.
    Has anyone an idea?

    Reply
  • How can I reach the edit fields with the tab key (tab stop)

    Posted by Legacy on 11/05/2001 12:00am

    Originally posted by: Keivan

    Hi,
    thank you for your Code.

    I want to reach every edit field with the tab stop. How is it possible? (Till now I must click with the mouse on every field. It is not comfortable)

    Thank you again for your help.

    Keivan

    Reply
  • How can I add an horizontal scrollbar to it.

    Posted by Legacy on 10/18/2001 12:00am

    Originally posted by: Dan

    Hi , your code is great and saved me a lot of time.

    Do you know how can I add an horizontal scrollbar for a long text properties ?

    10x

    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • Agile methodologies give development and test teams the ability to build software at a faster rate than ever before. Combining DevOps with hybrid cloud architectures give teams not just the principles, but also the technology necessary to achieve their goals. By combining hybrid cloud and DevOps: IT departments maintain control, visibility, and security Dev/test teams remain agile and collaborative Organizational barriers are broken down Innovation and automation can thrive Download this white paper to …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds