Click here to Skip to main content
Licence 
First Posted 30 Nov 1999
Views 269,026
Bookmarked 73 times

A Multi Column ComboBox

By | 30 Nov 1999 | Article
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

    About the Author

    Xiao Wu Guang



    United States United States

    Member



    Sign Up to vote   Poor Excellent
    Add a reason or comment to your vote: x
    Votes of 3 or less require a comment

    Comments and Discussions

     
    You must Sign In to use this message board. (secure sign-in)
     
    Search this forum  
     FAQ
        Noise  Layout  Per page   
      Refresh
    GeneralDropdown error,help,help, Pinmemberice_beauty122:18 9 Jun '09  
    GeneralOnGetText incorrect return value PinmemberBobMiller17:24 10 Mar '09  
    Generalvs 2005 PinmemberDexteR Jenkins4:24 21 Jun '08  
    Answercrashes and similar Pinmembergbjbaanb22:49 11 Dec '07  
    QuestionQuestion (Virtual List for more than 32736 items) ? Pinmemberana_v1239:22 25 Nov '06  
    Questionhow create multiline combobox PinmemberKondriSergey1:33 7 Feb '05  
    GeneralComboBox PinmemberAsha Rams22:09 1 Aug '04  
    GeneralFix for Windows XP and 2000 PinsussAnonymous8:11 14 Jul '04  
    GeneralRe: Fix for Windows XP and 2000 PinsussAnonymous12:25 10 Mar '05  
    Generalhelp needed Pinmemberspidey82018:40 11 Feb '04  
    GeneralDII PinmemberMarquis.D.J19:08 6 Nov '03  
    Generalnew version please ! PinmemberWiktor18:52 25 Sep '03  
    GeneralWindows 2000 and XP fix information PinmemberJohn Fisher11:40 2 Sep '03  
    GeneralRe: Windows 2000 and XP fix information Pinmemberctchen0:00 25 Sep '03  
    GeneralRe: Windows 2000 and XP fix information PinmemberJohn Fisher2:00 25 Sep '03  
    GeneralRe: Windows 2000 and XP fix information Pinmemberbradsmithatuw2:43 10 Oct '03  
    GeneralOnly 1 column PinmemberKrzyzak_71:36 2 Jun '03  
    Generala new version, please ! PinsussCynicannibal3:38 1 Apr '03  
    Generalmulticolumn comboBox Pinsussxrhstos pappas23:27 17 Mar '03  
    GeneralMulti column combo box Pinmemberm12222:35 15 Mar '03  
    GeneralRe: Multi column combo box Pinsusskondriksergey21:22 16 Mar '03  
    GeneralWARNING regarding XP PinmemberEarl Allen19:19 29 Nov '02  
    GeneralFor Windows2000 with VC6 SP5 PinmemberHiromitsu Hotta16:57 23 Sep '02  
    GeneralRe: For Windows2000 with VC6 SP5 Pinmemberheng098710:18 28 Jul '03  
    GeneralRe: For Windows2000 with VC6 SP5 Pinmemberice_beauty122:52 9 Jun '09  

    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.

    Permalink | Advertise | Privacy | Mobile
    Web01 | 2.5.120517.1 | Last Updated 1 Dec 1999
    Article Copyright 1999 by Xiao Wu Guang
    Everything else Copyright © CodeProject, 1999-2012
    Terms of Use
    Layout: fixed | fluid