Click here to Skip to main content
15,867,756 members
Articles / Desktop Programming / MFC

List ComboBox Control

Rate me:
Please Sign up or sign in to vote.
4.98/5 (14 votes)
23 Sep 2016CPOL2 min read 23.2K   1.1K   10   4
A ListCtrl ComboBox control

Introduction

This control enhances the classic CComboBox control, and puts in its dropdown list a CListCtrl, with all benefits that come after: drop down list could have multicolumn, checkboxes, ordering, etc.

Background

This control is related with this one: CTreeComboBox, the difference consists only in control that is encapsulated in the dropdown list.

Using the Code

In order to be used, this control must have 3 classes:

  • CListComboBox, derived from CComboBox
  • CComboListCtrl, derived from CListCtrl
  • CYourComboListCtrl, derived from CComboListCtrl

Description

The CYourComboListCtrl is only a customization of your CListCtrl that you want to use, but it must be derived from CComboListCtrl in order to have the applied functionality.

So, if you want this control hybrid, you just have to include 6 files, ListComboBox.h and cpp, ComboListCtrl.h and cpp, and an extension of CComboListCtrl, let's say MyComboListCtrl.h and cpp.

Once you have these files in your project, you can easily use this control just like this:

Put a CComboBox control on your form, but it must be type of CListComboBox, not CComoboBox only.

C#
//
// In your view header

#include "ListComboBox.h"
#include "MyComboListCtrl.h"

// and

 CListComboBox m_Combo2;
 CMyComboListCtrl* m_pListCtrl2;

// in your cpp file

CTestListComboView::CTestListComboView()
 : CFormView(CTestListComboView::IDD)
 ,m_pListCtrl2(NULL)
{
 m_pListCtrl2 = new CMyComboListCtrl;
 m_Combo2.SetListCtrl(m_pListCtrl2);
}

And after that, you just handle your m_pListCtrl2 as you want (configurating, populate with data, etc.)

You cand find more details in the attached sample project.

The enhanced combobox has several methods that help in using this hybrid control:

  • DisplayList() - Use this instead of native ShowDopDown() in order to show drop down menu
  • SetEditText(SetEditText(LPCTSTR lpszString) - To setup a text for edit combobox
  • SetEditItemData/GetEditItemData - To setup an itemdata for selected item, visible from CListComboBox object
  • SetListCtrl(CComboListCtrl* pListCtrl) - is setting the CComboListCtrl object as drop down list
  • IsControlActive() - Retrieve the state of drop down list
  • GetDroppedWidth() / GetDroppedHeight() - Return the width and height of drop down list
  • SetDroppedWidth() / SetDroppedHeight() - Setup the width and height of drop down list
  • SetEditTooltip() / GetEditTooltip() - Set/get the tooltip for edit combobox, that could be different than edit text
  • GetShowTooltip() / SetShowTooltip() - Activate / deactivate the tooltip for edit combobox
  • GetShowEditTooltipOverItem() / SetShowEditTooltipOverItem() - Set / Get the position of tooltip for edit combobox, to be shown over edit area, of above

Of course, there is another method available on this CComboBox that makes from this control a good choice for situations when you need an enhanced combobox.

I hope it helps you! P.S.

As far as I can, I will come back with new details about using this control.

History

  • 2016-09-23- Article published

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Romania Romania
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionPressing ALT + Down Arrow opens the default drop down window Pin
Plamen Petrov22-Oct-18 3:49
professionalPlamen Petrov22-Oct-18 3:49 
AnswerRe: Pressing ALT + Down Arrow opens the default drop down window Pin
Plamen Petrov23-Oct-18 21:03
professionalPlamen Petrov23-Oct-18 21:03 
QuestionHave you consider to post this as a tip? Pin
Nelek23-Sep-16 2:51
protectorNelek23-Sep-16 2:51 
AnswerRe: Have you consider to post this as a tip? Pin
_Flaviu23-Sep-16 3:11
_Flaviu23-Sep-16 3:11 

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.