CTreeCtrl::DeleteItem

调用此函数从树视图控件中删除项。

BOOL DeleteItem(
   HTREEITEM hItem 
);

参数

  • hItem
    要删除的树项的句柄。 如果 hitem 具有 TVI_ROOT 值,所有项目从树视图控件被删除。

返回值

非零,如果成功;否则为0。

示例

// Look at all of the root-level items
HTREEITEM hCurrent = m_TreeCtrl.GetChildItem(TVI_ROOT);
while (hCurrent != NULL) 
{
   // Get the text for the item. Notice we use TVIF_TEXT because
   // we want to retrieve only the text, but also specify TVIF_HANDLE
   // because we're getting the item by its handle.
   TVITEM item;
   TCHAR szText[1024];
   item.hItem = hCurrent;
   item.mask = TVIF_TEXT | TVIF_HANDLE;
   item.pszText = szText;
   item.cchTextMax = 1024;

   BOOL bWorked = m_TreeCtrl.GetItem(&item);

   // Try to get the next item
   hCurrent = m_TreeCtrl.GetNextItem(hCurrent, TVGN_NEXT);

   // If we successfuly retrieved an item, and the item's text
   // contains a lowercase letter 'e', delete the item.
   if (bWorked && _tcschr(item.pszText, 'e'))
      m_TreeCtrl.DeleteItem(item.hItem);
}

要求

Header: afxcmn.h

请参见

参考

CTreeCtrl选件类

层次结构图

CTreeCtrl::DeleteAllItems

CTreeCtrl::InsertItem