Sdílet prostřednictvím


CTreeCtrl::GetNextItem

Call this function to retrieve the tree view item that has the specified relationship, indicated by the nCode parameter, to hItem.

HTREEITEM GetNextItem(
   HTREEITEM hItem,
   UINT nCode 
) const;

Parameters

  • hItem
    Handle of a tree item.

  • nCode
    A flag indicating the type of relation to hItem. This flag can be one of the following values:

    • TVGN_CARET   Retrieves the currently selected item.

    • TVGN_CHILD   Retrieves the first child item of the item specified by the hItem parameter.

    • TVGN_DROPHILITE   Retrieves the item that is the target of a drag-and-drop operation.

    • TVGN_FIRSTVISIBLE   Retrieves the first visible item.

    • TVGN_LASTVISIBLE   Retrieves the last expanded item in the tree. This does not retrieve the last item visible in the tree-view window.

    • TVGN_NEXT   Retrieves the next sibling item.

    • TVGN_NEXTVISIBLE   Retrieves the next visible item that follows the specified item.

    • TVGN_PARENT   Retrieves the parent of the specified item.

    • TVGN_PREVIOUS   Retrieves the previous sibling item.

    • TVGN_PREVIOUSVISIBLE   Retrieves the first visible item that precedes the specified item.

    • TVGN_ROOT   Retrieves the first child item of the root item of which the specified item is a part.

Return Value

The handle of the next item if successful; otherwise NULL.

Remarks

This function will return NULL if the item being retrieved is the root node of the tree. For example, if you use this message with the TVGN_PARENT flag on a first-level child of the tree view's root node, the message will return NULL.

Example

For an example of using GetNextItem in a loop, see CTreeCtrl::DeleteItem.

// find the currently selected item
HTREEITEM hCurSel = m_TreeCtrl.GetNextItem(TVI_ROOT, TVGN_CARET);

// report it to the user
if (hCurSel == NULL)
{
   AfxMessageBox(_T("There is no selected item"));
}
else
{
   CString str;
   str.Format(_T("The currently selected item is \"%s\""),
      (LPCTSTR)m_TreeCtrl.GetItemText(hCurSel));
   AfxMessageBox((LPCTSTR)str);
}

Requirements

Header: afxcmn.h

See Also

Reference

CTreeCtrl Class

Hierarchy Chart

CTreeCtrl::SetItem

CTreeCtrl::GetChildItem

CTreeCtrl::GetItem

CTreeCtrl::SelectItem

CTreeCtrl::GetPrevSiblingItem

Other Resources

CTreeCtrl Members