Compartilhar via


CTreeCtrl::SetItemExpandedImageIndex

Sets the index of the image to display when the specified item of the current tree-view control is in the expanded state.

BOOL SetItemExpandedImageIndex(
     HTREEITEM hItem, 
     int iExpandedImage
);

Parameters

Parameter

Description

[in] hItem

Handle to a tree-view control item.

[in] iExpandedImage

The index of the image to display when the specified item is in the expanded state.

Return Value

true if this method is successful; otherwise, false.

Remarks

This method sends the TVM_SETITEM message, which is described in the Windows SDK. This method assigns the iExpandedImage parameter to the iExpandedImage member of a TVITEMEX structure, and then uses that structure in the message.

Requirements

Header: afxcmn.h

This method is supported in Windows Vista and later.

Additional requirements for this method are described in Build Requirements for Windows Vista Common Controls.

Example

The following code example defines a variable, m_treeCtrl, that is used to access the current tree-view control. The code example also defines an unsigned integer and several HTREEITEM variables. These variables are used in the next example.

public:
    // Variable to access tree control.
    CTreeCtrl m_treeCtrl;
    // Variable to access splitbutton control.
    CSplitButton m_splitbutton;
    // Accessibility identifier
    UINT accIdUS;
    // HTREEITEMs
    HTREEITEM hCountry;
    HTREEITEM hPA;
    HTREEITEM hWA;

The following code example is a trivial test to determine whether the CTreeCtrl::GetItemExpandedImageIndex method returns the value set by the CTreeCtrl::SetItemExpandedImageIndex method. In an earlier section of the code example, which is not shown, we created a tree-view that consists of a root country node for the United States, subnodes for the states of Pennsylvania and Washington, and tree items for cities in those states.

    CString str;
    CString msg = _T("The set and retrieved item expanded image ")
                  _T("indexes are%s equal.");
    int nSetItem = 0;
    m_treeCtrl.SetItemExpandedImageIndex( hCountry, nSetItem );
    int nItem = m_treeCtrl.GetItemExpandedImageIndex( hCountry );
    if (nItem == nSetItem)
        str.Format(msg, _T(""));
    else
        str.Format(msg, _T(" not"));
    AfxMessageBox(str, MB_ICONINFORMATION);

See Also

Reference

CTreeCtrl Class

Hierarchy Chart

TVM_SETITEM

TVITEMEX

CTreeCtrl::GetItemExpandedImageIndex

Other Resources

CTreeCtrl Members