List ComboBox Control
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 fromCComboBox
CComboListCtrl
, derived fromCListCtrl
CYourComboListCtrl
, derived fromCComboListCtrl
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.
//
// 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 nativeShowDopDown()
in order to show drop down menuSetEditText(SetEditText(LPCTSTR lpszString)
- To setup a text for editcombobox
SetEditItemData
/GetEditItemData
- To setup anitemdata
for selected item, visible fromCListComboBox
objectSetListCtrl(CComboListCtrl* pListCtrl)
- is setting theCComboListCtrl
object as drop down listIsControlActive()
- Retrieve the state of drop down listGetDroppedWidth()
/GetDroppedHeight()
- Return the width and height of drop down listSetDroppedWidth()
/SetDroppedHeight()
- Setup the width and height of drop down listSetEditTooltip()
/GetEditTooltip()
- Set/get the tooltip for editcombobox
, that could be different than edit textGetShowTooltip()
/SetShowTooltip()
- Activate / deactivate the tooltip for editcombobox
GetShowEditTooltipOverItem()
/SetShowEditTooltipOverItem()
- Set / Get the position of tooltip for editcombobox
, 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