Click here to Skip to main content
11,481,735 members (62,435 online)
Click here to Skip to main content

A Multi Column ComboBox

, 30 Nov 1999 298.6K 6.5K 78
Rate this:
Please Sign up or sign in to vote.
A multicolumn, customizable, editable combobox
  • Download demo project - 22 Kb
  • Download demo files - 6 Kb

    Do you want:

    • a multicolumn  combobox?
    • a title for each column?
    • to control the text color in a disabled combobox control?
    • to show/edit "description" in the edit control of combobox and get "id" instead?
    • to sort items in combobox as normal?

    If all your answers are yes, you can use my class CMultiColumnComboBox used in my project. It is a owner-draw combo box class, derived from class CComboBox, but it's very easy to use. As shown above, it's works exactly like a normal combo box. No matter how many columns a combo box has, you do not need to modify the class. You can set a column to be shown and get text from BoundColumn, even a combo box is "drop down" one or "simple" one. When you key in chars in the edit box of "drop down" or "simple" combo box, items are searched in ShowColumn, not BoundColumn, but the result is in BoundColumn. If you do not like gray color text in your combo box when it's disabled, you can change its color.

    How to use this control

    1. Put an Ownerdraw ComboBox in your resource dialog, copy  MultiColumnCpmboBox.cpp and MultiColumnComboBox.h to the directory of your workspace or project, and insert follow line at top of  your CPP file.
          #include MultiColumnComboBox.h
      
    2. Add new member variables dialog class.
          DDX_Control(pDX, IDC_COMBO1, m_ComboBoxControl1);
          DDX_CBString(pDX, IDC_COMBO1, m_ComboBoxString1);
      
    3. In message map function OnInitDialog, use FormaComboBox to set m_TotalColumn, m_BoundColumnn and m_ShowColumn, this function must be called before other function called.
          m_ComboBoxControl2.FormatComboBox(2, 0, 1);
      
    4. Then, use SetColumnWidth to set m_ColumnWidth for each column, use SetColumnAlignStyle to set m_ColumnAlignStyle for each column. If default value DT_LEFT is used, skip it. Use SetColumnTitle to set title for each column. If you do not want title, skip it.
          m_ComboBoxControl2.SetColumnWidth(150, 0);
          m_ComboBoxControl2.SetColumnAlignStyle(DT_LEFT, DT_CENTER);
          m_ComboBoxControl1.SetColumnTitle("ID", "DESCRIPTION");
      
    5. Use CMultiColumnComboBox::AddRow instead of CComboBox::AddString to add a row to the list box of a combo box.
          m_ComboBoxControl2.AddRow(ColumnString1, ColumnString0);
          m_ComboBoxControl4.AddRow(ColumnString0, ColumnString1, 
              ColumnString2, ColumnString3);
      
    6. As you see, now you can use it as a normal combo box.

    Notes:

    Function SetColumnWidth, SetColumnAlignStyle and AddRow can be called with a variable number of arguments. You can modify AddRow to works as Printf.
    If you need more help, free feel to ask me.

  • 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

    Xiao Wu Guang

    United States United States
    No Biography provided

    Comments and Discussions

     
    GeneralDropdown error,help,help, Pin
    ice_beauty19-Jun-09 23:18
    memberice_beauty19-Jun-09 23:18 
    GeneralOnGetText incorrect return value Pin
    BobMiller10-Mar-09 18:24
    memberBobMiller10-Mar-09 18:24 
    Generalvs 2005 Pin
    DexteR Jenkins21-Jun-08 5:24
    memberDexteR Jenkins21-Jun-08 5:24 
    Answercrashes and similar Pin
    gbjbaanb11-Dec-07 23:49
    membergbjbaanb11-Dec-07 23:49 
    QuestionQuestion (Virtual List for more than 32736 items) ? Pin
    ana_v12325-Nov-06 10:22
    memberana_v12325-Nov-06 10:22 
    Questionhow create multiline combobox Pin
    KondriSergey7-Feb-05 2:33
    memberKondriSergey7-Feb-05 2:33 
    GeneralComboBox Pin
    Asha Rams1-Aug-04 23:09
    memberAsha Rams1-Aug-04 23:09 
    GeneralFix for Windows XP and 2000 Pin
    Anonymous14-Jul-04 9:11
    sussAnonymous14-Jul-04 9:11 
    GeneralRe: Fix for Windows XP and 2000 Pin
    Anonymous10-Mar-05 13:25
    sussAnonymous10-Mar-05 13:25 
    Generalhelp needed Pin
    spidey82011-Feb-04 19:40
    memberspidey82011-Feb-04 19:40 
    GeneralDII Pin
    Marquis.D.J6-Nov-03 20:08
    memberMarquis.D.J6-Nov-03 20:08 
    Generalnew version please ! Pin
    Wiktor125-Sep-03 9:52
    memberWiktor125-Sep-03 9:52 
    GeneralWindows 2000 and XP fix information Pin
    John Fisher2-Sep-03 12:40
    memberJohn Fisher2-Sep-03 12:40 
    GeneralRe: Windows 2000 and XP fix information Pin
    ctchen25-Sep-03 1:00
    memberctchen25-Sep-03 1:00 
    GeneralRe: Windows 2000 and XP fix information Pin
    John Fisher25-Sep-03 3:00
    memberJohn Fisher25-Sep-03 3:00 
    GeneralRe: Windows 2000 and XP fix information Pin
    bradsmithatuw10-Oct-03 3:43
    memberbradsmithatuw10-Oct-03 3:43 
    GeneralOnly 1 column Pin
    Krzyzak_72-Jun-03 2:36
    memberKrzyzak_72-Jun-03 2:36 
    Generala new version, please ! Pin
    Cynicannibal1-Apr-03 4:38
    sussCynicannibal1-Apr-03 4:38 
    Generalmulticolumn comboBox Pin
    xrhstos pappas18-Mar-03 0:27
    sussxrhstos pappas18-Mar-03 0:27 
    GeneralMulti column combo box Pin
    m12215-Mar-03 23:35
    memberm12215-Mar-03 23:35 
    GeneralRe: Multi column combo box Pin
    kondriksergey16-Mar-03 22:22
    susskondriksergey16-Mar-03 22:22 
    GeneralWARNING regarding XP Pin
    Earl Allen29-Nov-02 20:19
    memberEarl Allen29-Nov-02 20:19 
    GeneralFor Windows2000 with VC6 SP5 Pin
    Hiromitsu Hotta23-Sep-02 17:57
    memberHiromitsu Hotta23-Sep-02 17:57 
    GeneralRe: For Windows2000 with VC6 SP5 Pin
    heng098728-Jul-03 11:18
    memberheng098728-Jul-03 11:18 
    GeneralRe: For Windows2000 with VC6 SP5 Pin
    ice_beauty19-Jun-09 23:52
    memberice_beauty19-Jun-09 23:52 
    GeneralNeed help: XP Visual Styles Problem Pin
    Kevin J22-Sep-02 17:49
    sussKevin J22-Sep-02 17:49 
    GeneralRe: XP Visual Styles Problem Pin
    littlesome3-Jul-07 2:11
    memberlittlesome3-Jul-07 2:11 
    GeneralResizing Pin
    Acreff18-Aug-02 1:56
    sussAcreff18-Aug-02 1:56 
    Generalchange column width Pin
    Dieter Hammer11-Jul-02 4:54
    sussDieter Hammer11-Jul-02 4:54 
    GeneralOnly one column and no titles shown Pin
    Robert60218-Jun-02 10:50
    memberRobert60218-Jun-02 10:50 
    GeneralRe: Only one column and no titles shown Pin
    PatrickM4-Aug-02 7:44
    memberPatrickM4-Aug-02 7:44 
    QuestionHow do we add double click? Pin
    mstr7-Jun-02 11:37
    membermstr7-Jun-02 11:37 
    GeneralDoes No Even Compile Pin
    Anonymous1-Apr-02 19:26
    memberAnonymous1-Apr-02 19:26 
    GeneralRe: Does No Even Compile Pin
    tejfel2-May-02 0:44
    membertejfel2-May-02 0:44 
    GeneralRe: Does No Even Compile Pin
    WREY11-Sep-02 14:17
    memberWREY11-Sep-02 14:17 
    GeneralRe: Does No Even Compile Pin
    NewHSKid11-Oct-04 8:42
    memberNewHSKid11-Oct-04 8:42 
    GeneralDrop down window no longer moves left when cut-off on the right Pin
    Jason Good21-Mar-02 8:11
    memberJason Good21-Mar-02 8:11 
    GeneralXP Items doesn´t appear the first time Pin
    Braulio Díez31-Jan-02 1:04
    memberBraulio Díez31-Jan-02 1:04 
    GeneralWinCE Pin
    Floppe29-Jan-02 22:50
    memberFloppe29-Jan-02 22:50 
    GeneralDisabled Control Pin
    Chris Meech3-Jan-02 9:39
    memberChris Meech3-Jan-02 9:39 
    GeneralUpdateData(FALSE) have a problem Pin
    Ricky Wang7-Dec-01 21:22
    memberRicky Wang7-Dec-01 21:22 
    GeneralUnhandled Exception in MFC42D.DLL Pin
    Denny19-Nov-01 12:34
    memberDenny19-Nov-01 12:34 
    GeneralRe: Unhandled Exception in MFC42D.DLL Pin
    Anonymous4-Aug-02 14:09
    sussAnonymous4-Aug-02 14:09 
    GeneralRe: Unhandled Exception in MFC42D.DLL Pin
    Anonymous4-Aug-02 14:10
    sussAnonymous4-Aug-02 14:10 
    Generaldeletion of a row Pin
    jithu23-Oct-01 22:46
    memberjithu23-Oct-01 22:46 
    Generalhttp://www.exontrol.com/sg.jsp?content=products/excombobox Pin
    Anonymous12-Oct-01 9:34
    memberAnonymous12-Oct-01 9:34 
    GeneralRe: http://www.exontrol.com/sg.jsp?content=products/excombobox Pin
    Braulio Díez31-Jan-02 0:59
    memberBraulio Díez31-Jan-02 0:59 
    QuestionMay Header Control Styles change to flat? Pin
    wadehan24-Sep-01 0:11
    memberwadehan24-Sep-01 0:11 
    GeneralDDX_CBString Cannot always get the edit text Pin
    pzlee22-Jul-01 22:50
    memberpzlee22-Jul-01 22:50 
    GeneralNon unique column lists Pin
    Chris Meech20-Jul-01 10:59
    memberChris Meech20-Jul-01 10:59 

    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
    Web02 | 2.8.150520.1 | Last Updated 1 Dec 1999
    Article Copyright 1999 by Xiao Wu Guang
    Everything else Copyright © CodeProject, 1999-2015
    Layout: fixed | fluid