How can I tell the combobox that it should store the index as value in the cell but display the associated choice?
The easiest way would be to use the CGXTabbedComboBox control that has been added in Objective Grid 5.0. There you could assign the following choice list to the cell:
SetStyleRange(CGXRange(6,1,8,1),
CGXStyle()
.SetControl(GX_IDS_CTRL_TABBED_COMBOBOX)
.SetChoiceList("one\t1\n"
"two\t2\n"
"three\t3\n@)
.SetUserAttribute(GX_IDS_UA_TABLIST_KEYCOL, _T("1"))
.SetUserAttribute(GX_IDS_UA_TABLIST_TEXTCOL, _T("0"))
.SetUserAttribute(GX_IDS_UA_TABLIST_SHOWALLCOLS, _T("0"))
);
This will display one, two or three in the cell but the index (1,2 or 3) will be stored as value. You can also change the value with SetValueRange(cell, 1);
If, for any reason you don't want to used tabbed comboboxes, here is a discussion how this was problem could be solved with earlier grid versions.
CGXComboBox
When constructing the combobox control object, you should specify GXCOMBO_DISPLAYCHOICE as flag.
The following two combobox controls are pre-defined in the grid (see mygridvw.cpp in the gridapp sample)
Example:
// use an integer as cell value
RegisterControl(GX_IDS_CTRL_ONEBASED_EX,
new CGXComboBox(this, GX_IDS_CTRL_ONEBASED_EX, GX_IDS_CTRL_ONEBASED_EX,
GXCOMBO_ONEBASED|GXCOMBO_DISPLAYCHOICE));
// use an zero-based integer as cell value
RegisterControl(GX_IDS_CTRL_ZEROBASED_EX,
new CGXComboBox(this, GX_IDS_CTRL_ZEROBASED_EX, GX_IDS_CTRL_ZEROBASED_EX,
GXCOMBO_ZEROBASED|GXCOMBO_DISPLAYCHOICE));
CGXComboBoxWnd
The ComboBoxWnd class maintains an attribute m_bDispChoice that lets you enable this feature. You should set this attribute when registering your combobox control object.
Example:
// CComboBox adapter with CBS_DROPDOWNLIST style
{
CGXComboBoxWnd* pWnd = new CGXComboBoxWnd(this);
pWnd->Create(WS_VSCROLL | CBS_DROPDOWNLIST, 12001);
pWnd->m_bFillWithChoiceList = TRUE;
pWnd->m_bWantArrowKeys = FALSE;
pWnd->m_nIndexValue = 0; // zero-based index
pWnd->m_bDispChoice = TRUE; // display choice
pWnd->m_bDropDownOnClick = FALSE; // do not dropdown the
// list when user clicks the first time on the cell
RegisterControl(IDS_CTRL_MYDROPDOWNLIST, pWnd);
}
You could then apply the combobox to cells with
SetStyleRange(CGXRange(nRow, nCol),
CGXStyle()
.SetControl(IDS_CTRL_MYDROPDOWNLIST)
.SetChoiceList("mon\ntue\nwed\nthu\nfri\nsat\nsun")
.SetValue(1) // tuesday
);