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.
#include "ListComboBox.h"
#include "MyComboListCtrl.h"
CListComboBox m_Combo2;
CMyComboListCtrl* m_pListCtrl2;
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