原来做了个tree控件,用来管理一系列item,可是每次添加item后,需要手动点击“+”号,才能打开树根,看到添加后的结果。就希望在添加一项后,树控件可以自动展开,用到了Expand函数:
m_ctrlTree.Expand(hRoot,TVE_EXPAND);
//hRoot指定要展开的树根(或子根),参数TVE_EXPAND用来执行展开树hRoot中的所有项。
哈哈!一句话搞定!现在与大家分享一下。
下面把CTreeCtrl::Expand 函数各参数的功能说明如下:
BOOL Expand( HTREEITEM hItem, UINT nCode );
返回值
Nonzero if successful; otherwise 0.
如果成功则返回非零值;否则返回0。
参数说明
hItem
nCode
- TVE_COLLAPSE
Collapses the list.收缩列表。 - TVE_COLLAPSERESET
Collapses the list and removes the child items.收缩列表并删除子项。 - TVE_EXPAND
Expands the list.展开列表。 - TVE_TOGGLE
Collapses the list if it is currently expanded or expands it if it is currently collapsed.如果列表当前是展开的则收缩列表;反之则展开列表。
备注
Call this function to expand or collapse the list of child items, if any, associated with the given parent item.此成员函数用来展开或收缩给定父项的子项列表(如果有)。
(原文地址:http://www.feiesoft.com/vc/_mfc_ctreectrl.3a3a.expand.htm