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:

  • GX_IDS_UA_TABLIST_TEXTCOL

  • which column contains the text to be displayed as text in the cell.

  • GX_IDS_UA_TABLIST_KEYCOL 

  • which column contains text to be stored as value in the cell.

  • GX_IDS_UA_TABLIST_SHOWALLCOLS

  • if all columns shall be shown or only the column with the display text (e.g., if you want to hide the value from the user).

  • GX_IDS_UA_TABLIST_TITLEROW

  • if the first row should be used for displaying column headers.

  • GX_IDS_UA_TABLIST_COLWIDTHS

  • column widths in pixels; example: “50,200,90”

  • default (if GX_IDS_UA_TABLIST_COLWIDTHS is empty), the optimal column width is computed based on the text size in the entries of each column.

  • GX_IDS_UA_TABLIST_SORTCOL

  • you sort the drop-down table by the specified column.

  • GX_IDS_UA_TABLIST_CHOICELISTID

  • a unique integer id to this attribute, you can speed up tabbed comboboxes a lot because then the choice list string can be reused among different cells and does not have to be reloaed for every different cell. The AttachForeignTable call (dao and odbc grid)  takes advantage of this user attribute.

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:

  • GX_IDS_CTRL_TABBED_COMBOBOX

  • implemented through CGXTabbedComboBox

  • derived from CGXComboBox

  • edit portion of list box is editable. When you type in characters, the remaining text will automatically be filled with a possible choice.

  • GX_IDS_CTRL_CBS_TABBED_DROPDOWNLIST

  • implemented through CGXTabbedComboBoxWnd

  • derived from CGXComboBoxWnd

  • uses the CBS_DROPDOWNLIST style

  • edit portion of list box is not editable

  • GX_IDS_CTRL_CBS_TABBED_DROPDOWN

  • implemented through CGXTabbedComboBoxWnd

  • derived from CGXComboBoxWnd

  • uses the CBS_DROPDOWN style

  • edit portion of list box is editable. When you type in characters, the remaining text will automatically be filled with a possible choice.

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