为啥cTreeCtrl只显示根节点
为什么cTreeCtrl只显示根节点?
我在对话框里放了一个CtreeCtrl控件,
然后在initaldialog里面加上了三条语句构建这个ctreectrl,
结果发现只有根节点(United states) 显示出来,其他的两个子结点(washington, Illinois)不显示,
大家能告诉我为什么吗?谢谢了。
顺便说明,即使我点击这个根节点,也看不到子节点。
BOOL CtreectrlexDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
HTREEITEM rt = m_TreeCtrl.InsertItem( _T("United Sates"),TVI_ROOT, TVI_LAST );
m_TreeCtrl.InsertItem( _T("Washington"),rt, TVI_LAST );
m_TreeCtrl.InsertItem( _T("Illinois"),rt, TVI_LAST );
return TRUE; // return TRUE unless you set the focus to a control
}
------解决方案--------------------
我在对话框里放了一个CtreeCtrl控件,
然后在initaldialog里面加上了三条语句构建这个ctreectrl,
结果发现只有根节点(United states) 显示出来,其他的两个子结点(washington, Illinois)不显示,
大家能告诉我为什么吗?谢谢了。
顺便说明,即使我点击这个根节点,也看不到子节点。
BOOL CtreectrlexDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
HTREEITEM rt = m_TreeCtrl.InsertItem( _T("United Sates"),TVI_ROOT, TVI_LAST );
m_TreeCtrl.InsertItem( _T("Washington"),rt, TVI_LAST );
m_TreeCtrl.InsertItem( _T("Illinois"),rt, TVI_LAST );
return TRUE; // return TRUE unless you set the focus to a control
}
------解决方案--------------------
- C/C++ code
HTREEITEM hItem,hSubItem; hItem = m_TreeCtrl.InsertItem(L"Parent1",TVI_ROOT); //在根结点上添加Parent1 hSubItem = m_TreeCtrl.InsertItem(L"Child1_1",hItem); //在Parent1上添加一个子结点 hSubItem = m_TreeCtrl.InsertItem(L"Child1_2",hItem,hSubItem); //在Parent1上添加一个子结点,排在Child1_1后面 hSubItem = m_TreeCtrl.InsertItem(L"Child1_3",hItem,hSubItem); hItem = m_TreeCtrl.InsertItem(L"Parent2",TVI_ROOT,hItem); hItem = m_TreeCtrl.InsertItem(L"Parent3",TVI_ROOT,hItem);
------解决方案--------------------
CTreeCtrl的Create风格参数如下,你可以选择是否展开之类的:
TVS_HASLINES 在父/子结点之间绘制连线
TVS_LINESATROOT 在根/子结点之间绘制连线
TVS_HASBUTTONS 在每一个结点前添加一个按钮,用于表示当前结点是否已被展开
TVS_EDITLABELS 结点的显示字符可以被编辑
TVS_SHOWSELALWAYS 在失去焦点时也显示当前选中的结点
TVS_DISABLEDRAGDROP 不允许Drag/Drop
TVS_NOTOOLTIPS 不使用ToolTip显示结点的显示字符
------解决方案--------------------
1楼和2楼的回答我觉得够了
楼主可以结贴了。