<< Return to Main Index

< Return to Class Index

class CGXTabbedComboBox: public CGXComboBox

The CGXTabbedComboBox class implements a tabbed combo box based on the existing CGXComboBox implementation.

Tabbed combo boxes allow you to display multiple columns in the drop-down part of the combo box. This lets you give the user additional information about the choices in the list.

Another benefit of tabbed combo boxes is that they allow you to store a key value in the cell but display some narrative text in the cell. An example is if you want the user to choose a fruit and only store a short key in your database:

    Fruits       Key

    Apple        AP

    Orange       OR

    Pineapple    PA

    ....

With ODBC or any other record sets, this lets you bind a specific column to a related table in the data source and display the related table in the drop-down list. Only the key value of the related table has to be stored in the grid.

Tabbed combo box is a popular feature in MS Access. MS Access served as an example for the implementation in Objective Grid. However, Objective Grid greatly extends the functionality of tabbed combo boxes.

How do I use tabbed combo boxes?

The entries in the drop-down tables can be specified through the choice list. Each column is separated through a tab character.

Example:

LPCTSTR szChoices =

    "Apple\tAP\n"

    "Orange\tOR\n"

    "Pineapple\tPA";

The first row can be optionally used for displaying a title.

CString sTitle = "Fruit\tKey\n";

The following user attributes specify the behavior of the tabbed combo box:

Example:

// key is in column 1

// text to be display is in column 0

// first entry in choice list shall be used for column headers

SetStyleRange(CGXRange(6,1,8,1),

    CGXStyle()

    .SetControl(GX_IDS_CTRL_TABBED_COMBOBOX)

    .SetChoiceList(sTitle + szChoiceList)

    .SetUserAttribute(GX_IDS_UA_TABLIST_KEYCOL, _T("1"))

    .SetUserAttribute(GX_IDS_UA_TABLIST_TEXTCOL, _T("0"))

    .SetUserAttribute(GX_IDS_UA_TABLIST_TITLEROW, _T("1"))

.SetUserAttribute(GX_IDS_UA_TABLIST_SORTCOL, _T("1"))  // sort by key

    );

- OR -

// hide the key value from the user

// show only the text to be displayed in the cell

SetStyleRange(CGXRange(6,1,8,1),

    CGXStyle()

    .SetControl(GX_IDS_CTRL_TABBED_COMBOBOX)

    .SetChoiceList(szChoiceList)

    .SetUserAttribute(GX_IDS_UA_TABLIST_KEYCOL, _T("1"))

    .SetUserAttribute(GX_IDS_UA_TABLIST_TEXTCOL, _T("0"))

    .SetUserAttribute(GX_IDS_UA_TABLIST_SHOWALLCOLS, _T("0"))

.SetUserAttribute(GX_IDS_UA_TABLIST_SORTCOL, _T("0"))  // sort by display text

    );

Tabbed combo boxes support bitmaps in cells. Therefore, you could easily extend the choice list with a bitmap.

Example:

LPCTSTR szChoices =

    "Apple\tAP\t#BMP(\"APPLE\")\n"

    "Orange\tOR\t#BMP(\"ORANGE\")\n"

    "Pineapple\tPA\t#BMP(\"PINEAPPLE\")";

Check out gridsvw9.cpp in the gridapp sample application for more examples.

For DAO and ODBC grids, we have added the method AttachForeignTable. This method lets you attach a foreign table to a specific column.

How does it work?

Objective Grid comes with three types of tabbed combo boxes:

As with CGXComboBox and CGXComboBoxWnd, the difference between CGXTabbedComboBox and CGXTabbedComboBoxWnd is that CGXTabbedComboBox better fits into the cell, whereas CGXTabbedComboBoxWnd displays a 3d-frame when active and therefore needs to be drawn slightly bigger than the cell when active. The 3d-frame is MFC CComboBox behavior that unfortunately can’t be turned off.

The advantage of CGXTabbedComboBoxWnd is that it is derived from the CComboBox class and therefore can offer all the functionality of the MFC CComboBox class (e.g., display a static edit portion by using the CBS_DROPDOWNLIST style).

Note

When you are using the CGXTabbedComboBox with a grid that is embedded in a dialog, you should override the dialog’s OnNcActivate method to avoid flickering of the dialog title bar. 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 OnNcActive in your CMainFrame class.

#include <gxall.h>

See Also

CGXTabbedComboBoxWnd CGXComboBox

CGXTabbedComboBox

Class Members