Objective Grid: Displaying a choice in a combobox and storing the index in the cell

Article ID: 221
Last updated: 04 Jun, 2018
Article ID: 221
Last updated: 04 Jun, 2018
Revision: 3
Views: 4313
Posted: 12 Jan, 2001
by Meltreger B.
Updated: 04 Jun, 2018
by Meltreger B.

Problem


How can I tell the combo box that it should store the index as a value in the cell but display the associated choice?


Cause



Action


The easiest way would be to use the CGXTabbedComboBox control. 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 1 two 2 three 3 ")
.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 combo boxes, here is a discussion how this was problem could be solved with earlier grid versions.

CGXComboBox

When constructing the combo box control object, you should specify GXCOMBO_DISPLAYCHOICE as flag.

The following two combo box 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 combo box 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 combo box to cells with:

SetStyleRange(CGXRange(nRow, nCol),
CGXStyle()
.SetControl(IDS_CTRL_MYDROPDOWNLIST)
.SetChoiceList("mon tue wed thu fri sat sun")
.SetValue(1) // Tuesday
);

This article was:   Helpful | Not helpful
Report an issue
Article ID: 221
Last updated: 04 Jun, 2018
Revision: 3
Views: 4313
Posted: 12 Jan, 2001 by Meltreger B.
Updated: 04 Jun, 2018 by Meltreger B.

Others in this category