Multi column Combo box (2)

First, I want to say, that I saw the article Multicolumn Combobox by Jakawan Ratiwanich, on www.codeguru.com. I inspected the piece of code, and I noticed that exist a array of items. That combo do not accept more than 200 items. In my mind, this is a inconvenient issue. So, I started to create a class CMultiColumnComboBox. Dealing with that very easy. The listbox of original combobox was replaced with a CListCtrl, so, when you will click in button's combo a lsitctrl will appear on the screen.

How user can use this control?

  1. Put in your resource dialog, a custom control, with window class name: MultiColumnComboBox.
  2. Add a new member in dialog class m_combo as CMultiColumnComboBox.
  3. In OnInitDialog subclass this member with
    m_combo.SubclassDlgItem(IDC_CUSTOM1, this),
    
    where IDC_CUSTOM1 is the ID of control in dialog.

How do you insert items?

Very easy. Here a snnipet code to insert:

    CListCtrl* pList = m_combo.GetListCtrl(); // call this function to retieve the listcontrol inside. 
    pList->InsertColumn(0, _T("Col 1"), LVCFMT_LEFT, 48); 
    pList->InsertColumn(1, _T("Col 2"), LVCFMT_LEFT, 48); 
    ... 

As you see, filling control with items is in fact filling the list control. Now the control is ready to use.

Notes:

- If the use want to add checkboxes to the lis control, he can call the following function:
ListView_SetExtendedListViewStyle(m_combo.GetListCtrl()->m_hWnd,
                                  LVS_EX_FULLROWSELECT | LVS_EX_CHECKBOXES ); 

By default, the extended styles of listcontrol are : LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT.

If you need more help, free feel to ask me.

Download demo project - 31 KB

Download source - 6.6 KB



Comments

  • How to use it's list in virtual mode to show 60000+ items (Win98) ?

    Posted by anand_study on 11/28/2006 08:18am

    This is a very nice control. Thanks. Any one tried to use list control of this multi-column combo ? I need to use it's list in virtual mode to show 60000+ items (Win98) ? Thanks for any help/hint. Anand

    Reply
  • List control with header

    Posted by molostov on 06/29/2005 03:59pm

    If list has header and the last item is selected, GetCurrentItem() returns -1.

    Reply
  • Proportionnal to Font Size? 2000 ?

    Posted by Legacy on 10/16/2001 12:00am

    Originally posted by: Michel DAVID

    Hi Mihai.

    I am interrested to know
    1) Does it work on 2000/XP ?
    2) Is it possible to make it higher (That means DY bigger) according to the Dialog font, like a regular CB that grows when the dialog font grows.

    Thank you very much.

    Michel DAVID
    MARNET

    Reply
  • a question

    Posted by Legacy on 09/28/2001 12:00am

    Originally posted by: Assia

    i need some help for creating a combo Box which control the item of a second Dialog Box on the same dialog.

    Unfortunatelly i hd an error occure for every try i made.

    Can someone help me for that.

    thank you in advance.

    Assia from Paris

    Reply
  • mouse wheel is not captured

    Posted by Legacy on 07/03/2001 12:00am

    Originally posted by: Ivaylo G.

    Hi Mihai,
    Thanks for control it is very practical!

    But I find some small bug about mouse wheel. When I use it, that is not captured from control but for dialog window.
    Can you give me some idea for that problem.

    Ivailo


    Reply
  • Minor bug in search

    Posted by Legacy on 10/13/2000 12:00am

    Originally posted by: Cesco

    The search always begins from the first element, so if two items share the same text the second is never found. Very simple solution: add an int member variable like m_last initialized as -1 in the constructor and modify the Search method like this:
    
    void CMultiColumnComboBox::Search(LPCTSTR lpszFindItem)
    {
    if (CListCtrl* pListCtrl = GetListCtrl())
    {
    LV_FINDINFO fInfo;
    fInfo.flags = LVFI_PARTIAL | LVFI_STRING;
    fInfo.psz = lpszFindItem;
    TRACE("Last was %d\n", m_last);
    int nItem = pListCtrl->FindItem(&fInfo, m_last);
    m_last = nItem;
    SetCurrentItem(nItem);
    pListCtrl->EnsureVisible(nItem, FALSE);
    }
    }
    By the way: Very cool control.

    Reply
  • Minor bug in search

    Posted by Legacy on 10/13/2000 12:00am

    Originally posted by: Cesco

    The search always begins from the first element, so if two items share the same text the second is never found. Very simple solution: add an int member variable like m_last initialized as -1 in the constructor and modify the Search method like this:
    
    void CMultiColumnComboBox::Search(LPCTSTR lpszFindItem)
    {
    if (CListCtrl* pListCtrl = GetListCtrl())
    {
    LV_FINDINFO fInfo;
    fInfo.flags = LVFI_PARTIAL | LVFI_STRING;
    fInfo.psz = lpszFindItem;
    TRACE("Last was %d\n", m_last);
    int nItem = pListCtrl->FindItem(&fInfo, m_last);
    m_last = nItem;
    SetCurrentItem(nItem);
    pListCtrl->EnsureVisible(nItem, FALSE);
    }
    }
    By the way, Very cool control.
    Cesco

    Reply
  • i want this control!!

    Posted by Legacy on 04/30/2000 12:00am

    Originally posted by: Mark Axmann

    I'm working on VB project that needs this control. How can I get a compiled .ocx of this control?? Or a VB code version.


    Thanks.
    Mark

    Reply
  • When in Combobox, Alt+F4 doesn't close the main window

    Posted by Legacy on 06/10/1999 12:00am

    Originally posted by: Magnus Johansson

    When in the customized combobox, Alt+F4 doesn't close the main window.
    Instead, it opens up the listbox.

    Why is that ?

    Reply
  • Very small change - Make it select EditBox contents when item selected:

    Posted by Legacy on 06/02/1999 12:00am

    Originally posted by: Bryan Napier

    Just one very minor thing to add to make it more like a combo box..  With a combobox, when you select an item
    from the listbox, the contents are copied to the editbox and then selected...  Here is my little change to do
    the same:
    
    

    void CMultiColumnComboBox::SelectCurrentItem()
    {
    int nIndex = GetCurrentItem();
    GetEdit()->SetWindowText(GetListCtrl()->GetItemText(nIndex, m_nColumnKey));\
    GetEdit()->SetSel(0, -1); // added by Bryan Napier, select entire edit box contents, like a real combo box
    //Notify the parent that one item was changed
    if (nIndex >= 0)
    if (CWnd* pParent = GetParent())
    pParent->SendMessage(m_nSelChange, (WPARAM)GetDlgCtrlID(), (LPARAM)m_hWnd);
    }

    Very remedial but who knows, might save someone 2 seconds!

    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Java developers know that testing code changes can be a huge pain, and waiting for an application to redeploy after a code fix can take an eternity. Wouldn't it be great if you could see your code changes immediately, fine-tune, debug, explore and deploy code without waiting for ages? In this white paper, find out how that's possible with a Java plugin that drastically changes the way you develop, test and run Java applications. Discover the advantages of this plugin, and the changes you can expect to see …

  • On-demand Event Event Date: September 10, 2014 Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild." This loop of continuous delivery and continuous feedback is how the best mobile …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds