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

Dialog to select and sort data with CListBox

, 17 Oct 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
Dialog box to choose data / Items and sort them

Introduction

I needed a dialog box to choose columns from database and sort thems. Such dialog is often seens, so I expected to find a ready to use solution on the web. Unfortunatly, I found nothing so I decided to create my own solution.

Background

The part to sort items on the second CListbox is described in article "Moving-listbox-items-up-and-down

Configuration in your project 

a) Add the following files in your project :
  • MovListBoxItem.h & .cpp 
  • ListBoxMoveItem.h & .cpp
  • WndResizer_2.h & .cpp
  • Function_1D.h & .cpp 
b) In Properties /  Link / input : Add on 'Additional dependances' : UxTheme.lib (on debug and release)

c) Create a dialog box in your project with the following data :

IDD_DIALOG1 DIALOGEX 0, 0, 301, 277
STYLE DS_SETFONT | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
CAPTION "Move ListBox Items and sort"
FONT 8, "MS Shell Dlg", 400, 0, 0x0
BEGIN
    LISTBOX         IDC_LIST1,7,23,115,223,LBS_SORT | LBS_NOINTEGRALHEIGHT | LBS_EXTENDEDSEL | WS_VSCROLL | WS_TABSTOP
    LISTBOX         IDC_LIST2,159,23,115,223,LBS_NOINTEGRALHEIGHT | LBS_EXTENDEDSEL | WS_VSCROLL | WS_TABSTOP
    PUSHBUTTON      ">",IDC_BUTTON1,128,99,25,14
    PUSHBUTTON      "<",IDC_BUTTON2,128,115,25,14
    PUSHBUTTON      ">>",IDC_BUTTON3,128,139,25,14
    PUSHBUTTON      "<<",IDC_BUTTON4,128,155,25,14
    LTEXT           "Available",IDC_STATIC_AVAILABLE,7,13,33,8
    LTEXT           "Selected",IDC_STATIC_SELECTED,158,13,38,8
    LTEXT           "(x/n)",IDC_STATIC_NBDISPO,49,13,33,8
    DEFPUSHBUTTON   "OK",IDOK,158,253,50,14
    PUSHBUTTON      "Cancel",IDCANCEL,224,253,50,14
    LTEXT           "(x/n)",IDC_STATIC_NB_SEL,201,13,33,8
    PUSHBUTTON      "^",IDC_BUTTON20,278,112,18,19
    PUSHBUTTON      "v",IDC_BUTTON21,278,136,18,19
END

d) Add variables :

  • Control CListBox IDC_LIST1            : m_cListBox_Dispo
  • Control CListBox IDC_LIST2            : m_cListBox_Selection
  • Value Static IDC_STATIC_NBDISPO : m_vNbDispo
  • Value Static IDC_STATIC_NB_SEL    : m_vNbSel

e) Include in your code :

//
#include "MovListBoxItem.h"
#include "ListBoxMoveItem.h"   
//

Using the code 

You need to transfert two variables in the dialog :

  • One for the complete list of items : A CString where each items is separated with "," : 
    m_vCompleteList // in example below 
    
  • One for the already selected (and sorted ) items previously saved (as settings data for example) : A CString where each items is separated with "," 
    m_vChoosenList // in example below
    
UpdateData( TRUE );    //FALSE : pour la mise à jour du contrôle //TRUE : pour récupérer la valeur dans la variable.
CListBoxMoveItem dialog(this, m_vCompleteList, m_vChoosenList);
if (dialog.DoModal() == IDOK)
{
  m_vChoosenList = dialog.Get_ListColSelection();
}
delete dialog;
UpdateData( FALSE );    //FALSE : pour la mise à jour du contrôle //TRUE : pour récupérer la valeur dans la variable. 

Points of Interest

Demo incluse a modified version of WndResizer from Mizan Rahman http://www.codeproject.com/KB/dialog/WndResizer.aspx (original can be used, modification is for hiding/showing controls) .

Remark: I tested multiple selection parts but not the single selection part.

History

  • 2013-10-14 : First published.   

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

MaxMax14

France France
No Biography provided

Comments and Discussions

 
GeneralMy vote of 3 PinmemberM.Ebrahimi.Ahouei14-Oct-13 20:58 
QuestionMissing download PinstaffSmitha Vijayan14-Oct-13 14:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.1411023.1 | Last Updated 17 Oct 2013
Article Copyright 2013 by MaxMax14
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid