工控编程吧
标题: 上位机MFC如何展开和选择树项 [打印本页]
作者: qq263946146 时间: 2019-7-29 14:24
标题: 上位机MFC如何展开和选择树项
这个功能相对简单,控件自己有提供相应函数。Expand,Select。
- //在树控件中添加连线和按钮
- m_ctrlTree.ModifyStyle(0, TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS);
- CString strText = _T("");
- //在树控件中插入项
- HTREEITEM hRoot = m_ctrlTree.InsertItem(_T("Root"));
- for (int i = 0; i < 4; i++)
- {
- strText.Format(_T("Item %d"), i);
- //在树控件中插入项
- HTREEITEM hParent = m_ctrlTree.InsertItem(strText, hRoot);
- for(int j = 0; j < 5; j++)
- {
- strText.Format(_T("SubItem %d %d"), i, j);
- //在树控件中插入项
- m_ctrlTree.InsertItem(strText, hParent);
- }
- //展开树项
- m_ctrlTree.Expand(hParent, TVE_EXPAND);
- }
- //展开树项
- m_ctrlTree.Expand(hRoot, TVE_EXPAND);
- //选择树项
- m_ctrlTree.Select(hRoot, TVGN_CARET);
复制代码
(, 下载次数: 0)