CMFCRibbonComboBox Class

The CMFCRibbonComboBox class implements a combo box control that you can add to a ribbon bar, a ribbon panel, or a ribbon popup menu.

Syntax

class CMFCRibbonComboBox : public CMFCRibbonEdit

Members

Constructors

Name Description
CMFCRibbonComboBox::CMFCRibbonComboBox Constructs a CMFCRibbonComboBox object.

Public Methods

Name Description
CMFCRibbonComboBox::AddItem Appends a unique item to the list box.
CMFCRibbonComboBox::DeleteItem Deletes a specified item from the list box.
CMFCRibbonComboBox::EnableDropDownListResize Specifies whether the list box can change size when it drops down.
CMFCRibbonComboBox::FindItem Returns the index of the first item in the list box that matches a specified string.
CMFCRibbonComboBox::GetCount Returns the number of items in the list box.
CMFCRibbonComboBox::GetCurSel Gets the index of the currently selected item in the list box.
CMFCRibbonComboBox::GetDropDownHeight Gets the height of the list box when the list box is dropped down.
CMFCRibbonComboBox::GetIntermediateSize Returns the size of the combo box as displayed in intermediate mode.
CMFCRibbonComboBox::GetItem Returns the string associated with an item at a specified index in the list box.
CMFCRibbonComboBox::GetItemData Returns the data associated with an item at a specified index in the list box.
CMFCRibbonComboBox::HasEditBox Indicates whether the control contains an edit box.
CMFCRibbonComboBox::IsResizeDropDownList Indicates whether or not the list box can be resized.
CMFCRibbonComboBox::OnSelectItem Called by the framework when the user selects an item in the list box.
CMFCRibbonComboBox::RemoveAllItems Deletes all items from the list box and clears the edit box.
CMFCRibbonComboBox::SelectItem Selects an item in the list box.
CMFCRibbonComboBox::SetDropDownHeight Sets the height of the list box when it is dropped down.

Remarks

The ribbon combo box consists of a list box combined with either a static label or label that can be edited by the user. You must specify which type you want when you create your ribbon combo box.

Example

The following example demonstrates how to construct an object of the CMFCRibbonComboBox class, add an item to the combo box, select an item in the combo box, and add a combo box to a panel.

// Create a simple combo box with two entries:
// The first parameter is the id of the combo box.
// The third parameter is the width of the combo box in pixels.
// The fourth parameter is the display label of the combo box.
// The fifth parameter is the index of the small image of the combo box.
CMFCRibbonComboBox *pComboSimple = new CMFCRibbonComboBox(-1, FALSE, -1, 0, -1);

// Add two items to the combo box and select the first item in the list:
pComboSimple->AddItem(_T("Hi!"));
pComboSimple->AddItem(_T("Hello!"));
pComboSimple->SelectItem(0);

// Add combo button to "Favorites" panel:
// CMFCRibbonPanel* pPanelFavorites
pPanelFavorites->Add(pComboSimple);

Inheritance Hierarchy

CObject

CMFCRibbonBaseElement

CMFCRibbonButton

CMFCRibbonEdit

CMFCRibbonComboBox

Requirements

Header: afxribboncombobox.h

CMFCRibbonComboBox::AddItem

Appends a unique item to the list box.

virtual INT_PTR AddItem(
    LPCTSTR lpszItem,
    DWORD_PTR dwData=0);

Parameters

lpszItem
[in] The string of the item to add.

dwData
[in] The data associated with the item to add.

Return Value

The zero-based index of the appended item.

CMFCRibbonComboBox::CMFCRibbonComboBox

Constructs a CMFCRibbonComboBox object.

public:
CMFCRibbonComboBox(
    UINT nID,
    BOOL bHasEditBox=TRUE,
    Int nWidth=-1,
    LPCTSTR lpszLabel=NULL,
    Int nImage=-1);

protected:
CMFCRibbonComboBox();

Parameters

nID
[in] The ID of the combo box.

bHasEditBox
[in] TRUE if you want an edit box within the control; FALSE otherwise.

nWidth
[in] Width of the combo box in pixels; or -1 for the default width.

lpszLabel
[in] The display label of the combo box.

nImage
[in] The small image index of the combo box.

Remarks

The default width is 108 pixels.

CMFCRibbonComboBox::DeleteItem

Deletes a specified item from the list box.

BOOL DeleteItem(int iIndex);
BOOL DeleteItem(DWORD_PTR dwData);

BOOL DeleteItem(LPCTSTR lpszText);

Parameters

iIndex
[in] The zero-based index of the item to be deleted.

dwData
[in] The data associated with the item to be deleted.

lpszText
[in] The string of the item to be deleted. If there are multiple items with the same string, the first item is deleted.

Return Value

TRUE if the specified item has been deleted; otherwise, FALSE.

Remarks

CMFCRibbonComboBox::EnableDropDownListResize

Specifies whether the list box can change size when it drops down.

void EnableDropDownListResize(BOOL bEnable=FALSE);

Parameters

bEnable
[in] TRUE to enable resizing; FALSE to disable resizing.

Remarks

When resizing is enabled, the list box will change size to fit the items it displays.

CMFCRibbonComboBox::FindItem

Returns the index of the first item in the list box that matches a specified string.

int FindItem(LPCTSTR lpszText) const;

Parameters

lpszText
[in] The string of an item in the list box.

Return Value

The zero-based index of the item; or -1 if the item is not found.

Remarks

CMFCRibbonComboBox::GetCount

Returns the number of items in the list box.

INT_PTR GetCount() const;

Return Value

The number of items in the list box, or 0 if the list box contains no items.

Remarks

CMFCRibbonComboBox::GetCurSel

Gets the index of the currently selected item in the list box.

int GetCurSel() const;

Return Value

The zero-based index of the currently selected item in the list box; or -1 if no item is selected.

CMFCRibbonComboBox::GetDropDownHeight

Gets the height of the list box when the list box is dropped down.

int GetDropDownHeight();

Return Value

The height, in pixels, of the list box.

Remarks

CMFCRibbonComboBox::GetIntermediateSize

Returns the size of the combo box as displayed in intermediate mode.

virtual CSize GetIntermediateSize(CDC* pDC);

Parameters

pDC
[in] Pointer to a device context for the combo box.

Return Value

The size of the combo box.

Remarks

The size returned is based on the size of the combo box when it displays small images.

CMFCRibbonComboBox::GetItem

Returns the string associated with an item at a specified index in the list box.

LPCTSTR GetItem(int iIndex) const;

Parameters

iIndex
[in] The zero-based index of an item in the list box.

Return Value

A pointer to the string that is associated with the item; otherwise, NULL if the index parameter is invalid, or if the index parameter is -1 and there is no item selected in the combo box.

Remarks

CMFCRibbonComboBox::GetItemData

Returns the data associated with an item at a specified index in the list box.

DWORD_PTR GetItemData(int iIndex) const;

Parameters

iIndex
[in] The zero-based index of an item in the list box.

Return Value

The data associated with the item; or 0 if the item does not exist, or if the index parameter is -1 and there is no selected item in the list box.

CMFCRibbonComboBox::HasEditBox

Indicates whether the control contains an edit box.

BOOL HasEditBox() const;

Return Value

TRUE if the control contains an edit box; otherwise, FALSE.

Remarks

CMFCRibbonComboBox::IsResizeDropDownList

Indicates whether or not the list box can be resized.

BOOL IsResizeDropDownList() const;

Return Value

TRUE if the list box can be resized; otherwise FALSE. CMFCRibbonComboBox::EnableDropDownListResize

Remarks

You can enable list box resizing by using the CMFCRibbonComboBox::EnableDropDownListResize method.

CMFCRibbonComboBox::OnSelectItem

Called by the framework when a user selects an item in the list box.

virtual void OnSelectItem(int nItem);

Parameters

nItem
[in] The index of the selected item.

Remarks

Override this method if you want to process a user input selection.

CMFCRibbonComboBox::RemoveAllItems

Deletes all items from the list box and clears the edit box.

void RemoveAllItems();

Remarks

CMFCRibbonComboBox::SelectItem

Selects an item in the list box.

BOOL SelectItem(int iIndex);
BOOL SelectItem(DWORD_PTR dwData);

BOOL SelectItem(LPCTSTR lpszText);

Parameters

iIndex
[in] The zero-based index of an item in the list box.

dwData
[in] The data associated with an item in the list box.

lpszText
[in] The string of an item in the list box.

Return Value

TRUE if the method was successful; otherwise FALSE.

Remarks

CMFCRibbonComboBox::SetDropDownHeight

Sets the height of the list box when it is dropped down.

void SetDropDownHeight(int nHeight);

Parameters

nHeight
[in] The height, in pixels, of the list box.

Remarks

The default height is 150 pixels.

See also

Hierarchy Chart
Classes
CMFCRibbonEdit Class