共用方式為


CTreeCtrl::DeleteItem

呼叫這個函式會刪除從樹狀檢視控制項中的項目。

BOOL DeleteItem(
   HTREEITEM hItem 
);

參數

  • hItem
    要刪除之樹狀目錄的控制代碼。 如果 hitemTVI_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