Subselection Dialog


Class: CSubSelection
Category: Dialog
MFC version: 4.2,
Unicode: Yes (altough not tested)

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 sample gives you a sample whith 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:
1. Add the two files CSubSelectionDlg.h and CSubSelectionDlg.cpp into your project.
2. Make a new dialog resource with the two CListBoxes. You can make one ore both boxes as 'single', 'multiple' or 'extended' selectable.
3. The first CListBox should be made 'sorted'.
4. Now call the class wizard and make a CDialog (CMySelectionDlg in the sample) derived class attached to your new dialog template.
5. Now change the base class of your new dialog from CDialog to CSubSelectionDlg. Also include the CSubSelectionDlg.h file where needed.
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 / 2 with the name of your CListbox resource ID.
7. Change the dialog constructor to include these ID's :
CMySelection::CMySelection(CWnd* pParent /*=NULL*)
	: CSubSelectionDlg(CMySelection::IDD,CMySelection::IDD2,CMySelection::IDD3, pParent)
{
....

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

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

Now lean back and to enjoy the newest addition to your project. For details refer to the sample below.

Of course there is room for enhancements, like drag and drop, support for icons, or property sheets.

Download demo project - 109 KB

Download source - 4 KB



Comments

  • There is a memory leak.

    Posted by Legacy on 11/03/1998 12:00am

    Originally posted by: Tongzhe Cui

    Running this terminator, you will find out that the memeory is not fully released.
    If your target program allocating a lot of memory, after several times of terminating it, your memory will be exhausted.

    Anyway, it is still useful.


    Reply
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 …

  • It's no secret what keeps CIOs up at night. Mobile, cloud, data, security, and social have become the "five imperatives," the drivers of business progress, innovation, and competitive differentiation. Business leaders around the world want to hear how other companies are succeeding. How are they applying the latest technologies? How did they get started? What outcomes are they achieving? Read this online magazine for success stories from organizations like the NBA, Pfizer, and San Jose State University as they …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds