Click here to Skip to main content
11,802,442 members (67,391 online)
Click here to Skip to main content

Subselection Dialog

, 17 Nov 1999 47.2K 1.4K 22
Rate this:
Please Sign up or sign in to vote.
Subselection dialog.



Often when the user can select some items from a predefined set and has to sort them at the same time, a dialog similar to the one above is used. For instance, for selecting a set of fields for a database access or for exporting to a file.

The CSubSelectionDlg is derived from CDialog and can be used as a base for your own class. The included download gives you a sample with all the possibilities (CMySelectionDlg). You can create your own dialog template, but it needs (at least) two CListBoxes.

Here is a step by step guide for including the CSubSelectionDlg into your project:


Step 1. Add the two files CSubSelectionDlg.h and CSubSelectionDlg.cpp into your project.

Step 2. Make a new dialog resource with the two CListBoxes. You can make one ore both boxes as 'single', 'multiple' or 'extended' selectable.

Step 3. The first CListBox should be made 'sorted'.

Step 4. Now call the class wizard and make a CDialog (CMySelectionDlg in the sample) derived class attached to your new dialog template.

Step 5. Now change the base class of your new dialog from CDialog to CSubSelectionDlg. Also include the CSubSelectionDlg.h file where needed.

Step 6. Include the following line in your .h file:

// tell the constructor about the two CListBoxes

and replace the IDC_SELECTION_LIST1/IDC_SELECTION_LIST2 with the name of your CListbox resource ID.

Step 7. Change the dialog constructor to include these IDs:

   CMySelection::CMySelection(CWnd* pParent /*=NULL*/)
        : CSubSelectionDlg(CMySelection::IDD,
        CMySelection::IDD2,CMySelection::IDD3, pParent)

Step 8. Now map any buttons etc. to the base class members. Note: None of these mappings are needed, but you will not get the attached functionality Frown | :-(


Step 9. Now you can overwrite the virtual functions InitListBox1() and InitListBox2() to give the boxes something to work with.

Now lean back to enjoy the newest addition to your project. For details, refer to the sample project. Of course, there is room for enhancements, like drag and drop, support for icons, or property sheets.


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

Daniel Zuppinger
Chief Technology Officer
Switzerland Switzerland
Professional IT developer since 1983. First projects with Cobol, then Pascal, Modula2, C and since Visual C++ 1.0 also with C++. Works since 1986 as Consultant, between 1990 and 2008 for Infobrain in Switzerland, currently employed by enValue (also Switzerland).
Current field is the project management and development of software for Bank applications.
Married, two daughters, Hobbies : Paragliding, Orienteering, Mountainbiking, Photography

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.151002.1 | Last Updated 18 Nov 1999
Article Copyright 1999 by Daniel Zuppinger
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid