Click here to Skip to main content
Click here to Skip to main content

Subselection Dialog

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

subselect_dialog.gif

Introduction

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:

Steps

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
         enum { IDD2 = IDC_SELECTION_LIST1, IDD3 = IDC_SELECTION_LIST2 };
 //

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 | :-(

 //
    ON_LBN_DBLCLK(IDC_SELECTION_LIST1, OnDblclkSelectionList1)
    ON_LBN_DBLCLK(IDC_SELECTION_LIST2, OnDblclkSelectionList2)
    ON_BN_CLICKED(IDC_MOVEDOWN, OnMovedown)
    ON_BN_CLICKED(IDC_MOVEUP, OnMoveup)
    ON_BN_CLICKED(IDC_EXCLUDE, OnExclude)
    ON_BN_CLICKED(IDC_INCLUDE, OnInclude)
    ON_BN_CLICKED(IDC_SELECTALL, OnSelectAll) 
 //

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.

License

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

Share

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

Comments and Discussions

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