Click here to Skip to main content
15,885,757 members
Articles / Desktop Programming / MFC
Article

The Ultimate Toolbox Multi Combobox

Rate me:
Please Sign up or sign in to vote.
4.47/5 (4 votes)
25 Aug 2007CPOL1 min read 60.6K   1.9K   18   10
A flexible multi-column combobox control from the Ultimate Toolbox

Visit the Ultimate Toolbox main page for an overview and configuration guide to the Ultimate Toolbox library.

Source code and project files for this sample can be found in the samples\gui\MultiCombo directory of the sample projects download.

Overview

Image 1

The COXMulticomboBox class is derived from MFC's CComboBox and implements a combo box with more than one column. A version of this type of control can be seen in action in Microsoft Access.

Features

  • Can have multiple columns in each item of the combo box.
  • Only one column will be transferred to the edit (or static) control. The other columns are shown in the dropdown listbox as extra information.
  • The interface is identical to CComboBox with an extra column number parameter.

Usage

The ComboBox should be created as CBS_OWNERDRAWFIXED. If you want variable height rows you can use CBS_OWNERDRAWVARIABLE, but you will need to handle the MeasureItem notification yourself. If you don't specify CBS_HASSTRINGS, you have to handle the DrawItem and CompareItem methods and maintain each column items data yourself.

If the COXMultiComboBox is used as a control in dialog box then set the above said (ownerdrawn) styles in the dialog templates.

In the header of your MFC CDialog derived class, you can subclass a CComboBox member variable set by the Class Wizard by simply replacing the class name in the declaration in the AFX_DATA area.

The code from the samples\gui\MultiCombo:

C++
#include "OXMultiComboBox.h"


#include "UTB64Bit.h"

/////////////////////////////////////////////////////////////////////////////

// CMComboDlg dialog

class CMComboDlg : public CDialog
{
// Construction

public:
    CMComboDlg(CWnd* pParent = NULL);    // standard constructor

// Dialog Data

    //{{AFX_DATA(CMComboDlg)

    enum { IDD = IDD_MCOMBO_DIALOG };
    COXMultiComboBox m_MCombo;

All that's needed is a bit of initialization in OnInitDialog:

C++
m_MCombo.SetColumnCount(3);
m_MCombo.SetColumnWidth(0,100);
m_MCombo.SetColumnWidth(1,120);
m_MCombo.SetColumnWidth(2,20);
LPTSTR str1[] = {_T("David"), _T("Cunningham"),
    _T("1")};
LPTSTR str2[] = {_T("Troy") , _T("Marchand"),
    _T("2")};
LPTSTR str3[] = {_T("Andrei"), _T("Zenkovitch"),
    _T("3")};
LPTSTR str4[] = {_T("Ghazi"), _T("Wadi"),
    _T("4")};

The compiled HTML help documentation contains a complete COXMulticomboBox class reference.

History

Initial CodeProject release August 2007.

License

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


Written By
Web Developer
Canada Canada
In January 2005, David Cunningham and Chris Maunder created TheUltimateToolbox.com, a new group dedicated to the continued development, support and growth of Dundas Software’s award winning line of MFC, C++ and ActiveX control products.

Ultimate Grid for MFC, Ultimate Toolbox for MFC, and Ultimate TCP/IP have been stalwarts of C++/MFC development for a decade. Thousands of developers have used these products to speed their time to market, improve the quality of their finished products, and enhance the reliability and flexibility of their software.
This is a Organisation

476 members

Comments and Discussions

 
QuestionSource code is missing Pin
_Flaviu25-Mar-14 21:02
_Flaviu25-Mar-14 21:02 
QuestionVertical scrollbar can not show correctly. Pin
maplewang24-Mar-14 20:34
maplewang24-Mar-14 20:34 
QuestionShows up incorrectly on second monitor Pin
peon123416-Sep-09 8:36
peon123416-Sep-09 8:36 
AnswerRe: Shows up incorrectly on second monitor Pin
Tim Deveaux16-Sep-09 10:30
Tim Deveaux16-Sep-09 10:30 
GeneralRe: Shows up incorrectly on second monitor [modified] Pin
peon123416-Sep-09 12:29
peon123416-Sep-09 12:29 
GeneralRe: Shows up incorrectly on second monitor Pin
Tim Deveaux16-Sep-09 13:09
Tim Deveaux16-Sep-09 13:09 
Generaldocumentation (chm file) not found Pin
mensoeng21-Oct-08 0:19
mensoeng21-Oct-08 0:19 
GeneralRe: documentation (chm file) not found Pin
Tim Deveaux21-Oct-08 6:38
Tim Deveaux21-Oct-08 6:38 
GeneralMissing column headers Pin
jsumm28-Mar-08 11:33
jsumm28-Mar-08 11:33 
GeneralRe: Missing column headers Pin
Tim Deveaux28-Mar-08 14:08
Tim Deveaux28-Mar-08 14:08 

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

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