Compartilhar via


CTreeCtrl::SetCheck

Call this member function to set the check state for a tree control item.

BOOL SetCheck( 
   HTREEITEM hItem, 
   BOOL fCheck = TRUE  
);

Parameters

  • hItem
    The HTREEITEM to receive the check state change.

  • fCheck
    Indicates whether the tree control item is to be checked or unchecked. By default, SetCheck sets the item to be checked.

Return Value

Nonzero if successful; otherwise 0.

Remarks

When the tree control item is checked (fCheck set to TRUE), the item appears with an adjacent checkmark.

Example

UINT uCount = m_TreeCtrl.GetVisibleCount();
HTREEITEM hItem = m_TreeCtrl.GetFirstVisibleItem();

// Toggle the check state of all the visible items. 
for (UINT i = 0; i < uCount; i++)
{
   ASSERT(hItem != NULL);
   m_TreeCtrl.SetCheck(hItem, !m_TreeCtrl.GetCheck(hItem));
   hItem = m_TreeCtrl.GetNextVisibleItem(hItem);
}

To use checkboxes, set TVS_CHECKBOXES before populating the tree control.

m_TreeCtrl.ModifyStyle(0, TVS_CHECKBOXES);

HTREEITEM aItem = m_TreeCtrl.InsertItem(_T("AAA"));
m_TreeCtrl.SetCheck(aItem);

Requirements

Header: afxcmn.h

See Also

Reference

CTreeCtrl Class

Hierarchy Chart

CTreeCtrl::GetCheck