<< Return to Main Index

< Return to Class Index

class CGXComboBox: public CGXEditControl

The CGXComboBox class implements a text input control that can be used to display and edit text in cells. The user can modify this text in place or select an item from a drop-down list box .

As with any other control, the user can change any style attributes with the CGXStyleSheet dialog.

By default, the list of choices which are displayed in the drop-down list is determined through the SetChoiceList attribute of the style object, but is also possible to fill the list box at runtime by subclassing CGXComboBox and overriding the virtual method OnFillDroppedList.

See the attached example showing how to override GetStyleRowCol and determine the choice list at runtime. This is very useful if the choice list depends on other cells’ values. Before you start subclassing CGXComboBox and override the OnFillDroppedList member to fill the drop-down list at runtime, consider whether overriding GetStyleRowCol might be an easier solution. There will be no difference in performance.

See the description of CGXEditControl for other style attributes that specify the appearance of the cell.

The following control ids are predefined in Objective Grid:

You can apply combo boxes to cells with

   SetStyleRange(range,
      CGXStyle()
         .SetControl(GX_IDS_CTRL_COMBOBOX)
         .SetValue("Item 1")
         .SetChoiceList("Item 0\nItem 1\nItem 2");
      );

If you want to use an index as value for the combo box, you may call

   SetStyleRange(range,
      CGXStyle()
         .SetControl(GX_IDS_CTRL_ZEROBASED_EX)
         .SetValue(1)
         .SetChoiceList("Item 0\nItem 1\nItem 2");
      );

The cell will display “Item 1” in both cases, but in the first sample, the text is stored as value in the style object, and in the second sample, the index is stored in the style object, so you can later simply call

   nIndex = atoi(GetValueRowCol(nRow, nCol));

to determine the index of the entry selected by the user.


Note: Objective Grid also provides an alternative combo-box control. The difference between CGXComboBoxWnd and CGXComboBox is that CGXComboBoxWnd is derived from the Windows standard combo-box control CcomboBox, whereas CGXComboBox is a CGXEditControl with a small button at the right side of the input area. CGXComboBox has the advantage of fitting better into cells (needs less row-height), whereas CGXComboBoxWnd offers full CComboBox functionality.

Note: When you are using the CGXComboBox with a grid that is a control 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.

#include <gxall.h>

See Also

CGXGridCore::RegisterControl CGXStyle::SetControl CGXComboBoxWnd CGXEditControl CGXStyle

CGXComboBox

Class Members