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.


- If the use want to add checkboxes to the lis control, he can call the following function:
                                  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

This article was originally published on June 21st, 1999

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date