查找节点,并返回该节点
HTREEITEM GroupTree::FindTreeItem(HTREEITEM item,CString& strText)
{
HTREEITEM hFind;
if(item == NULL)
return NULL;
while(item!=NULL)
{
if(m_pTree->GetItemText(item) == strText)
return item;
if(m_pTree->ItemHasChildren(item))
{
item = m_pTree->GetChildItem(item);
hFind = FindTreeItem(item,strText);
if(hFind)
{
return hFind;
}
else
item= m_pTree->GetNextSiblingItem(m_pTree->GetParentItem(item));
}
else
{
item = m_pTree->GetNextSiblingItem(item);
if(item == NULL)
return NULL;
}
}
return item;
}
设置为高亮:
m_pTree->Select(hitem, TVGN_DROPHILITE);
代码片段:
void GroupTree::SetCarFocus(TCHAR* carNum)
{
CString itemStr(carNum);
HTREEITEM hitem = FindTreeItem(m_pTree->GetRootItem(),itemStr);
if(hitem == NULL)
{
return;
}
m_pTree->SelectItem(hitem);
m_pTree->Select(hitem, TVGN_DROPHILITE);
}