After clicking on a node in the tree, the set of child nodes of the current node is displayed using the method of starting the database, which causes the complexity of the data processing and the slow speed of the program. After my repeated consideration, I will revise the procedure as follows:
One, will Returntreechilds (CString strcuritem), the code changes as follows: //----------------提取当前所选择项的子项文本所组成的字符串------------------------
CString CTreeDataDlg::ReturnTreeChilds(HTREEITEM hP)
{
CString text="";
//取出当前的Item值
text=m_ctrlTree.GetItemText(hP);
//取子项的Item值
HTREEITEM hC;
hC=m_ctrlTree.GetChildItem(hP);
while(true)
{
//-----------判断是否有子项,如果有,则递归调用-----------
if (m_ctrlTree.GetChildItem(hC)!=NULL)
{ text+=(","+ReturnTreeChilds(hC));}
else
{text+=(","+m_ctrlTree.GetItemText(hC));}
//----------------判断是否有兄弟项,如果有,则将它的内容添加进去---
if (m_ctrlTree.GetNextSiblingItem(hC)==NULL)
break;
HTREEITEM hBC;
hBC=m_ctrlTree.GetNextSiblingItem(hC);
hC=hBC;
}
return text;
} Note:
1. When the program calls, first the value of the current node, the value into text;
2. A handle to the current item, taking the handle of its subkey, where there are or are no child nodes;
At this point, we can use M_ctrltree.getchilditem (HC)!=null to determine if there are any child nodes in the current node, and if there are child nodes, loop to invoke the Returntreechilds (Htreeitem hP) function; The value of this node is added to the text.
3. Determine if the node has sibling nodes, if there are sibling nodes, then jump to step 2nd, loop execution, if not, then jump out of the while loop.
4. Returns the text value.
(ii) Modify the void Ctreedatadlg::onselchangedtree1 (nmhdr* pnmhdr, lresult* pResult) code as follows:
void Ctreedatadlg::onselchangedtree1 (nmhdr* pnmhdr, lresult* pResult)
{
nm_treeview* Pnmtreeview = (nm_treeview*) pnmhdr;
Todo:add your control notification handler code here
//--------------------------------------------------------
Htreecurrent=m_ctrltree.getselecteditem ();
Htreeparent=m_ctrltree.getparentitem (M_ctrltree.getselecteditem ());
-------------------The tree control's icon changes---------
M_ctrltree.setitemimage (htreecurrent,1,true);
//----------------------------------------------
Treeparent=m_ctrltree.getitemtext (htreeparent);
Htreecurrent=m_ctrltree.getselecteditem ();
---------------------process the corresponding display content in Listtree--------------
-----------------get the current item and sub items-----------------------
if (M_ctrltree.getchilditem (htreecurrent)!=null)
{//-------------if a subkey is recursive, returns the value of itself and the subkey---------
M_stredit=returntreechilds (htreecurrent);
}
Else
{
M_stredit=m_ctrltree.getitemtext (htreecurrent);
}
UpdateData (false);//child content displayed in edit control
//---------------------------------------------------
*presult = 0;
}
In this way, when you click on the tree node, the program automatically collects the values set of the current node and child nodes.