Hide

SftTree/DLL 7.5 - Tree Control

Display
Print

Collapse

Collapses a parent item.

C

BOOL WINAPI SftTree_Collapse(HWND hwndCtl, int index, BOOL fPreserve);
BOOL WINAPI SftTreeSplit_Collapse(HWND hwndCtl, int index, BOOL fPreserve);

C++

BOOL CSftTree::Collapse(int index, BOOL fPreserve = TRUE);
BOOL CSftTreeSplit::Collapse(int index, BOOL fPreserve = TRUE);

Parameters

hwndCtl

The window handle of the tree control.

index

The zero-based index of the item to be collapsed. If -1 is specified, all items on level 0 are collapsed.

fPreserve

Set to TRUE to preserve the expand/collapse state of dependent items made no longer visible. A subsequent call to Expand will restore the items with the remembered expand/collapse state. If FALSE is specified, the expand/collapse state is not preserved.

Returns

The return value is TRUE if successful, otherwise FALSE is returned.

Comments

The Collapse function collapses a parent item.

Collapse collapses the specified parent item index, hides all dependent items and saves the expand/collapse state of all dependent items (if fPreserve is set to TRUE), so it can be restored by a subsequent call to Expand.

In a tree control using a virtual data source, this function cannot be used.

Examples

C

                    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;
                 }
                case SFTTREEN_EXPANDALL: { // expand all
                    int index;
                    index = SftTree_GetExpandCollapseIndex(hwndCtl);/* Get item to expand/collapse */

C++

    /* 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);
}

/* Respond to numeric keypad multiply key.                 */

void CSampleView::OnExpandAll()

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