Hide

SftTree/DLL 7.5 - Tree Control

Display
Print

ItemExpand

Defines an item's expand status.

C

BOOL WINAPI SftTree_GetItemExpand(HWND hwndCtl, int index);
BOOL WINAPI SftTree_SetItemExpand(HWND hwndCtl, int index, BOOL fExpand, BOOL fDepth);
BOOL WINAPI SftTreeSplit_GetItemExpand(HWND hwndCtl, int index);
BOOL WINAPI SftTreeSplit_SetItemExpand(HWND hwndCtl, int index, BOOL fExpand, BOOL fDepth);

C++

BOOL CSftTree::GetItemExpand(int index) const;
BOOL CSftTree::SetItemExpand(int index, BOOL fExpand = TRUE, BOOL fDepth = FALSE);
BOOL CSftTreeSplit::GetItemExpand(int index) const;
BOOL CSftTreeSplit::SetItemExpand(int index, BOOL fExpand = TRUE, BOOL fDepth = FALSE);

Parameters

hwndCtl

The window handle of the tree control.

index

The zero-based index of the item for which the expand status is to be retrieved or set.

fExpand

Set to TRUE to expand the item or FALSE to collapse the item.

fDepth

Set to TRUE to expand the item's indirect dependents in addition to the immediate dependents. This parameter is ignored if fExpand is set to FALSE.

Returns

GetItemExpand returns the current expand status of the specified item, TRUE if one or more dependent items are visible (the item is expanded), FALSE if no dependents are visible or if the item doesn't have any dependents.

SetItemExpand returns TRUE if the function was successful, otherwise FALSE is returned.

Comments

The GetItemExpand and SetItemExpand functions define an item's expand status.

SetItemExpand does not preserve the expand/collapse state of dependent items. Use the Collapse function instead, which can optionally preserve this information.

An item can be expanded/collapsed under program control using SetItemExpand. To determine if an item can be expanded, GetDependentCount can be used.

An item must currently be shown in order to be expanded or collapsed using this function. Use SetItemShown to make an item visible.

SetItemExpand only takes effect when an item is a parent item (has child items), otherwise it is ignored and SetItemExpand will return FALSE. When items are added to a collapsed parent item (using the AddString, InsertString and the ItemLevel functions), the parent item is automatically expanded.

In a tree control using a virtual data source, SetItemExpand cannot be used and an error is returned.

Examples

C

                case SFTTREEN_LBUTTONDBLCLK_TEXT:
                case SFTTREEN_LBUTTONDOWN_BUTTON:
                case SFTTREEN_LBUTTONDBLCLK_BUTTON: {
                    int index;
                    BOOL fExpand, fControl;
                    /* Get current position */
                    index = SftTree_GetExpandCollapseIndex(hwndCtl);/* Get caret location */
                    /* Check if item is expanded */
                    fExpand = SftTree_GetItemExpand(hwndCtl, index);
                    /* If the CONTROL key is pressed, expand all dependent levels */
                    fControl = (BOOL)(GetKeyState(VK_CONTROL)&0x8000);
                    if (fExpand)
                        SftTree_Collapse(hwndCtl, index, TRUE);
                    else
                        SftTree_Expand(hwndCtl, index, TRUE, fControl);
                    break;

C++

/* components.  The events handled here can be changed to  */
/* suit your application.                                  */

void CSampleView::OnLButtonExpandCollapse()
{
    /* get index of item to expand/collapse */
    int index = m_Tree.GetExpandCollapseIndex();
    /* get current expand/collapsed status */
    BOOL fExpanded = m_Tree.GetItemExpand(index);
    /* if control key is used we'll expand all dependents */
    BOOL fDepth = (::GetKeyState(VK_CONTROL)&0x8000);

    if (fExpanded)
        m_Tree.Collapse(index, TRUE);
    else
        m_Tree.Expand(index, TRUE, fDepth);

See Also C/C++ API | Categories | Notifications