Wednesday, December 17, 2008

How to validate a Tree item in Tree Control [VC++] ?

Validating a node in Tree view.

In our product DocuMight client requires cut, copy, paste and delete with multiple selection.
Here I occurred a situation to validate previously selected items , but I didn’t find any  direct method in CTreeCtrl to validate a HTREEITEM .

I tried the following code.

bool IsItemExists(CTreeCtrl *pTree,HTREEITEM hItem)
{
      bool bExists = false;
      TVITEM item;
      item.hItem = hItem;
      item.mask = TVIF_STATE;
      item.stateMask = 0;
      item.state = 0;
      if( TRUE == ::SendMessage(pTree->m_hWnd, TVM_GETITEM, 0, (LPARAM)&item))
      {
            bExists = true;
      }
      return bExists;
}

In  the above code SendMessage will fail if the hItem is not valid.

 

No comments: