用VC实现按数据库记录构建树控件
2008-11-13 19:30:38 来源:WEB开发网7.处理TreeCtrl控件的点击(OnClick)和改变选择项(SelchangedTree)事件:
void CTreeDataDlg::OnSelchangedTree1(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
//--------------------------------------------------------
hTreeCurrent=m_ctrlTree.GetSelectedItem ();
hTreeParent=m_ctrlTree.GetParentItem(m_ctrlTree.GetSelectedItem ());
//-------------------树型控件的图标更改---------
m_ctrlTree.SetItemImage(hTreeCurrent,1,true );
//----------------------------------------------
TreeCurrent="''"+m_ctrlTree.GetItemText(hTreeCurrent)+"''";
TreeParent=m_ctrlTree.GetItemText (hTreeParent);
//---------------------处理ListTree中的相应显示内容--------------
//-------------提取树中当前项及其子项的内容------
hTreeCurrent=m_ctrlTree.GetSelectedItem ();
m_strEdit=TreeCurrent+ReturnTreeChilds(m_ctrlTree.GetItemText(hTreeCurrent));
UpdateData(false);//子项内容显示到Edit控件中
//---------------------------------------------------
*pResult = 0;
}
void CTreeDataDlg::OnClickTree1(NMHDR* pNMHDR, LRESULT* pResult)
{
//-------------------树型控件的图标还原---------
m_ctrlTree.SetItemImage(hTreeCurrent,0,true );
//----------------------------------------------
*pResult = 0;
}
三.在BOOL CTreeDataDlg::OnInitDialog()中添加以下代码: TreeAddTree();
本文效果图:
总结:
这个程序主要是在数据库中进行操作,主干是两个递归成员函数;对于递归,让你自己来理解吧!
更多精彩
赞助商链接