Click here to Skip to main content
11,928,987 members (54,260 online)
Click here to Skip to main content
Add your own
alternative version


80 bookmarked

Super Combo Box - combo-box with columns, colors and more

, 12 Apr 2004
Rate this:
Please Sign up or sign in to vote.
A CComboBox derived class that contains colors, columns, bold fonts, and images.

Sample Image - SuperComboBox.jpg


I was looking around for a CComboBox derived class that would combine some features I needed - multiple columns, colors, icons and more.

Some of these features are found in other controls, but not under one roof, so I've decided to put them all together, in a simple way that will also have room for future growth.


This class is a CComboBox derived class that enhances its functionalities:

  1. Multi-columns, when each column's width is controllable.
  2. An optional image-list can be supplied and an image can be set to the left of each row.
  3. Color of each row can be set.
  4. Each row can be bolded.

The code is based on Alex Hazanov's ComboBox Bold, just took it a bit further... thanks Alex.


The WIN32/MFC implementation of a CComboBox provides DWORD element - Item Data, accessed via the SetItemData() and GetItemData() for storing extra information for each item of the combo-box. I used this member to store all the extra data I need to know of each row. This data is stored in the nested ItemData structure which is constructed for each element in the combo-box:

struct ItemData
    ItemData() : crTextColor(RGB(0,0,0)),nImageIndex(-1),bBold(FALSE),dwItemData(0){}
    COLORREF crTextColor;                // Row's color.
    int nImageIndex;                     // Index of the image in the image-list.
    std::map<int,CString> mapStrings;    // Map of string of all columns.
    BOOL bBold;                          // TRUE if the row is bolded.
    DWORD dwItemData;                    // Giving back the Item Data to the user...

All the new interface functions are added for setting the extra attributes of the combo-box by modifying the ItemData structure, and invalidating the combo-box.

For not loosing the original functionality of the CComboBox's SetItemData() and GetItemData(), the ItemData contains a DWORD member as well, that is accessed via the CComboBoxSuper.

A vector of all columns' width stores the width of all columns, and the size of this vector is also the number of columns in the combo-box.

Most of the job is done in the DrawItem function. This function is called for each item's drawing, and reads its item data, and draw the item accordingly.

Another function implemented is the virtual OnDeleteItem, which is called each time an element is removed from the combo-box, and deletes the ItemData of the element deleted from the combo-box, including ResetContent().


To use in a dialog - add a normal combo to the dialog, and replace the class from CComboBox to CComboBoxSuper.

Make sure to change the combo style to Owner Drawn Fixed and Has String in the resource editor, or by code.

To create on the fly - call create of the CComboBoxSuper object, and don't forget the styles.

Note: I always used the combo as a drop-list, in dropdown you get the first column's text only for editing.

During init function or all around the code, the following functions can be called:

  1. Setting to column number, and column width:

    void SetColumnCount(int nColumnCount); 
    /** Sets the number of columns to use - 
    new columns are inserted at default width. */
    void SetColumnWidth(int nColumnIndex, int nWidth); 
    /** Sets the width of a specific column. */
    m_ctrlSuperCombo.SetColumnWidth(0, 100);
  2. Adding rows the combo (normal CComboBox function):

    m_ctrlSuperCombo.AddString("Row 1");
    m_ctrlSuperCombo.AddString("Row 2");
  3. Adding sub-item strings:

    void SetItemText(int nItemIndex, int nColumn, CString str); 
    /** Sets an item or sub-item text. */
  4. Setting a row color:

    void SetItemColor(int nItemIndex, COLORREF rcTextColor); 
    /** Sets a row's color. */
    m_ctrlSuperCombo.SetItemColor(1, RGB(255,0,0));
    m_ctrlSuperCombo.SetItemColor(2, RGB(0,128,0));
  5. Setting a row to bold (default is not bolded for all added rows):

    void SetItemBold(int nItemIndex, BOOL bBold = TRUE); 
    /** Set a specific row to bold. */
    m_ctrlSuperCombo.SetItemBold(1, FALSE);
  6. Setting images:

    void SetImageList(CImageList* pImageList); 
    /** Sets the image list to use - will be show 
    only if SetUseImage is called. */
    void SetItemImage(int nItemIndex, int nImageIndex); 
    /** Sets a row's image index. */
    void SetUseImage(BOOL bUseImage=TRUE) 
    /** Sets to TRUE for using the image list, 
    of FALSE to disable the use of the image-list. */
    m_ctrlSuperCombo.SetItemImage(1, 1);


  • 20-03-2004 : Version 1.0 - First release.
  • 03-04-2004 : Change in documentations according to readers' requests.


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

Web Developer
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralIt works (here is a method to auto adjust the column sizes and the dropdown width) Pin
g_d15-Sep-14 12:44
memberg_d15-Sep-14 12:44 
QuestionGood, It is my favorite Pin
maplewang2-Aug-12 1:23
membermaplewang2-Aug-12 1:23 
Thanks for sharing.
SuggestionCode : Auto Size Implementation Pin
RAJKUMARV23-Mar-12 4:13
memberRAJKUMARV23-Mar-12 4:13 
SuggestionAuto Sizing - Columns Pin
RAJKUMARV15-Mar-12 22:04
memberRAJKUMARV15-Mar-12 22:04 
QuestionWhat finally made this work for me. Pin
bramoin9-Mar-12 12:48
memberbramoin9-Mar-12 12:48 
QuestionLicense? Pin
cmconti13-Jul-11 9:22
membercmconti13-Jul-11 9:22 
QuestionCombo-box's dropdown button color? Pin
ddas-edEN24-Jul-08 0:36
memberddas-edEN24-Jul-08 0:36 
QuestionDoes it work in a DLL? Pin
Victor Monteverde9-Nov-07 10:18
memberVictor Monteverde9-Nov-07 10:18 
AnswerNevermind - WM_DRAWITEM Pin
Victor Monteverde12-Nov-07 8:02
memberVictor Monteverde12-Nov-07 8:02 
GeneralDon't work in Vs 2005 Pin
FilippoCSM6-Nov-07 3:31
memberFilippoCSM6-Nov-07 3:31 
QuestionGetOrCreateItemData Bug [modified] Pin
forkit29-Oct-07 15:52
memberforkit29-Oct-07 15:52 
GeneralErrors compiling with VS2005 Pin
C++ Hacker2-May-07 23:44
memberC++ Hacker2-May-07 23:44 
GeneralRe: Errors compiling with VS2005 Pin
forkit31-Oct-07 5:05
memberforkit31-Oct-07 5:05 
GeneralRe: Errors compiling with VS2005 Pin
C++ Hacker11-Nov-07 23:03
memberC++ Hacker11-Nov-07 23:03 
Question.Net? Pin
Member #247019224-Jan-07 6:17
memberMember #247019224-Jan-07 6:17 
GeneralAdded functionality: disabled items Pin
patrickp16-Jan-07 6:44
memberpatrickp16-Jan-07 6:44 
GeneralRe: Added functionality: disabled items Pin
ronhash29-Jan-07 10:11
memberronhash29-Jan-07 10:11 
QuestionBackground color Pin
TheIronFist12-Dec-06 11:33
memberTheIronFist12-Dec-06 11:33 
AnswerRe: Background color Pin
TheIronFist29-Dec-06 2:15
memberTheIronFist29-Dec-06 2:15 
GeneralRe: Background color Pin
ronhash29-Jan-07 10:13
memberronhash29-Jan-07 10:13 
QuestionDrop-down button color Pin
ddas-edEN24-Jul-08 0:34
memberddas-edEN24-Jul-08 0:34 
QuestionCombobox is 3 pixels bigger in height than normal? Pin
Fuzzychaos29-Oct-06 10:23
memberFuzzychaos29-Oct-06 10:23 
AnswerRe: Combobox is 3 pixels bigger in height than normal? Pin
ronhash29-Oct-06 16:16
memberronhash29-Oct-06 16:16 
AnswerRe: Combobox is 3 pixels bigger in height than normal? Pin
Fuzzychaos30-Oct-06 16:13
memberFuzzychaos30-Oct-06 16:13 
GeneralInital value shown in super combor box Pin
doctorrie9-Apr-06 16:10
memberdoctorrie9-Apr-06 16:10 
GeneralRe: Inital value shown in super combor box Pin
ronhash20-Apr-06 14:20
memberronhash20-Apr-06 14:20 
QuestionCComboBoxEx compatibility ? Pin
naflat29-Sep-05 7:34
membernaflat29-Sep-05 7:34 
AnswerRe: CComboBoxEx compatibility ? Pin
Anonymous2-Oct-05 2:24
sussAnonymous2-Oct-05 2:24 
GeneralRe: CComboBoxEx compatibility ? Pin
naflat3-Oct-05 2:15
membernaflat3-Oct-05 2:15 
GeneralGDI Leak Pin
msr.perfect18-Jul-05 23:42
membermsr.perfect18-Jul-05 23:42 
Generalnew version Pin
Joerg Tiedemann10-Jun-05 8:36
memberJoerg Tiedemann10-Jun-05 8:36 
GeneralRe: new version Pin
ronhash10-Jun-05 9:19
memberronhash10-Jun-05 9:19 
GeneralRe: new version Pin
Joerg Tiedemann14-Jun-05 2:58
memberJoerg Tiedemann14-Jun-05 2:58 
QuestiondwItemData - shouldn't it be DWORD_PTR? Pin
Filther28-Jan-05 6:42
memberFilther28-Jan-05 6:42 
GeneralBound Columns or select return to Edit Pin
PatrickM17-Dec-04 11:44
memberPatrickM17-Dec-04 11:44 
GeneralEditable columns Pin
Malis23-Jul-04 10:33
memberMalis23-Jul-04 10:33 
GeneralRe: Editable columns Pin
ronhash28-Jul-04 11:25
memberronhash28-Jul-04 11:25 
GeneralC# Pin
celsojp20-May-04 11:18
membercelsojp20-May-04 11:18 
GeneralGetOrCreateItemData should initialize ItemData struct! Pin
Thomas Haase23-Apr-04 1:16
memberThomas Haase23-Apr-04 1:16 
GeneralRe: GetOrCreateItemData should initialize ItemData struct! Pin
ronhash24-Apr-04 12:42
memberronhash24-Apr-04 12:42 
GeneralRe: GetOrCreateItemData should initialize ItemData struct! Pin
Thomas Haase25-Apr-04 23:39
memberThomas Haase25-Apr-04 23:39 Pin
jedyking14-Apr-04 6:28
memberjedyking14-Apr-04 6:28 
GeneralWrong param at ImageList_Create Pin
Thomas Haase7-Apr-04 3:08
memberThomas Haase7-Apr-04 3:08 
GeneralQuestion related to Itemdata Pin
Albert Hermann30-Mar-04 1:59
memberAlbert Hermann30-Mar-04 1:59 
GeneralRe: Question related to Itemdata Pin
ronhash30-Mar-04 2:03
memberronhash30-Mar-04 2:03 
GeneralRe: Question related to Itemdata Pin
Albert Hermann30-Mar-04 4:24
memberAlbert Hermann30-Mar-04 4:24 
GeneralRe: Question related to Itemdata Pin
ronhash30-Mar-04 7:36
memberronhash30-Mar-04 7:36 
GeneralMinor problem with sample project... Pin
whatisron28-Mar-04 7:16
memberwhatisron28-Mar-04 7:16 
GeneralRe: Minor problem with sample project... Pin
ronhash28-Mar-04 7:52
memberronhash28-Mar-04 7:52 
GeneralWow! Pin
Bamaco220-Mar-04 11:03
memberBamaco220-Mar-04 11:03 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.151126.1 | Last Updated 13 Apr 2004
Article Copyright 2004 by ronhash
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid