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.
class CMFCRibbonComboBox : public CMFCRibbonEdit
Name | Description |
---|---|
CMFCRibbonComboBox::CMFCRibbonComboBox | Constructs a CMFCRibbonComboBox object. |
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. |
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.
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);
Header: afxribboncombobox.h
Appends a unique item to the list box.
virtual INT_PTR AddItem(
LPCTSTR lpszItem,
DWORD_PTR dwData=0);
lpszItem
[in] The string of the item to add.
dwData
[in] The data associated with the item to add.
The zero-based index of the appended item.
Constructs a CMFCRibbonComboBox
object.
public:
CMFCRibbonComboBox(
UINT nID,
BOOL bHasEditBox=TRUE,
Int nWidth=-1,
LPCTSTR lpszLabel=NULL,
Int nImage=-1);
protected:
CMFCRibbonComboBox();
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.
The default width is 108 pixels.
Deletes a specified item from the list box.
BOOL DeleteItem(int iIndex);
BOOL DeleteItem(DWORD_PTR dwData);
BOOL DeleteItem(LPCTSTR lpszText);
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.
TRUE if the specified item has been deleted; otherwise, FALSE.
Specifies whether the list box can change size when it drops down.
void EnableDropDownListResize(BOOL bEnable=FALSE);
bEnable
[in] TRUE to enable resizing; FALSE to disable resizing.
When resizing is enabled, the list box will change size to fit the items it displays.
Returns the index of the first item in the list box that matches a specified string.
int FindItem(LPCTSTR lpszText) const;
lpszText
[in] The string of an item in the list box.
The zero-based index of the item; or -1 if the item is not found.
Returns the number of items in the list box.
INT_PTR GetCount() const;
The number of items in the list box, or 0 if the list box contains no items.
Gets the index of the currently selected item in the list box.
int GetCurSel() const;
The zero-based index of the currently selected item in the list box; or -1 if no item is selected.
Gets the height of the list box when the list box is dropped down.
int GetDropDownHeight();
The height, in pixels, of the list box.
Returns the size of the combo box as displayed in intermediate mode.
virtual CSize GetIntermediateSize(CDC* pDC);
pDC
[in] Pointer to a device context for the combo box.
The size of the combo box.
The size returned is based on the size of the combo box when it displays small images.
Returns the string associated with an item at a specified index in the list box.
LPCTSTR GetItem(int iIndex) const;
iIndex
[in] The zero-based index of an item in the list box.
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.
Returns the data associated with an item at a specified index in the list box.
DWORD_PTR GetItemData(int iIndex) const;
iIndex
[in] The zero-based index of an item in the list box.
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.
Indicates whether the control contains an edit box.
BOOL HasEditBox() const;
TRUE if the control contains an edit box; otherwise, FALSE.
Indicates whether or not the list box can be resized.
BOOL IsResizeDropDownList() const;
TRUE if the list box can be resized; otherwise FALSE. CMFCRibbonComboBox::EnableDropDownListResize
You can enable list box resizing by using the CMFCRibbonComboBox::EnableDropDownListResize method.
Called by the framework when a user selects an item in the list box.
virtual void OnSelectItem(int nItem);
nItem
[in] The index of the selected item.
Override this method if you want to process a user input selection.
Deletes all items from the list box and clears the edit box.
void RemoveAllItems();
Selects an item in the list box.
BOOL SelectItem(int iIndex);
BOOL SelectItem(DWORD_PTR dwData);
BOOL SelectItem(LPCTSTR lpszText);
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.
TRUE if the method was successful; otherwise FALSE.
Sets the height of the list box when it is dropped down.
void SetDropDownHeight(int nHeight);
nHeight
[in] The height, in pixels, of the list box.
The default height is 150 pixels.