class CGXCheckListComboBox: public CGXComboBox
The CGXCheckListComboBox class implements a drop-down list that allows the user to make multiple selections.
The list box entries and the cell text will be specified with the choice list. The selected items are stored as an integer value.
The first entry in the choice list is the text to be displayed in the cell. All other entries specify the possible choices.
Example:
LPCTSTR szMultiChoiceList =
_T("Click Me\n")
_T("One\n")
_T("Two\n")
_T("Three\n")
_T("Four\n")
_T("Five\n")
_T("Six\n")
_T("Seven\n")
_T("Eight\n")
_T("Nine\n")
_T("Ten\n");
The value is a long integer value. Each entry in the choice list corresponds to a bit in the long integer.For example, each of the previous entries is associated with the following integer values:
Width1Width3Width1527 Width3Width1417 Width3Width1650 Choice List | Hex Value | Binary ValueWidth1Width3Width1527 Width3Width1417 Width3Width1650 |
Width1Width3Width1527 Width3Width1417 Width3Width1650 no selection | 0x00 | 0000 0000Width1Width3Width1527 Width3Width1417 Width3Width1650 |
One | 0x01 | 0000 0001Width1Width3Width1527 Width3Width1417 Width3Width1650 |
Two | 0x02 | 0000 0010Width1Width3Width1527 Width3Width1417 Width3Width1650 |
Three | 0x04 | 0000 0100Width1Width3Width1527 Width3Width1417 Width3Width1650 |
Four | 0x08 | 0000 1000Width1Width3Width1527 Width3Width1417 Width3Width1650 |
Five | 0x10 | 0001 0000Width1Width3Width1527 Width3Width1417 Width3Width1650 |
Width1Width3Width1527 Width3Width1417 Width3Width1650 …. | … | …Width1Width3Width1527 Width3Width1417 Width3Width1650 |
All of the individual entries can be combined, as for example the selection "One, Two and Four" is represented with hex value 0x08 (binary: 00001011)
Here is how you can apply the checklist box to cells and specify the selected items:
CString strCheck;
strCheck.Format(_T("%ld"), 0x01|0x02|0x04);
SetStyleRange(CGXRange().SetRows(nRow+1),
CGXStyle()
.SetControl(GX_IDS_CTRL_CHECKLIST_COMBOBOX)
.SetChoiceList(szMultiChoiceList)
.SetValue(strCheck) // Each checked item is a zero-based index
);
When you want to determine which items have been selected by the user, you should call GetValueRowCol().
Example:
LONG l = _ttol(GetValueRowCol(nRow, nCol));
if (l&0x01)
TRACE("Item 1 is selected");
if (l&0x02)
TRACE("Item 2 is selected");
if (l&0x04)
TRACE("Item 3 is selected");
Note
When you are using the CGXCheckListComboBox with a grid that is embedded in a dialog, you should override the dialog’s OnNcActivate method to prevent the dialog title bar from flickering. The following code should be added to your dialog class:
BOOL CSample1Dialog::OnNcActivate(BOOL bActive)
{
if (GXDiscardNcActivate())
return TRUE;
return CDialog::OnNcActivate(bActive);
}
With a CGXGridView, you should override OnNcActivate in your CMainFrame class.
You need MFC 4.0 or higher to be able to use CGXCheckListComboBox !
#include <gxall.h>