CTreeCtrl 的CheckBox为何去不掉?

青稞 2010-02-21 02:52:35
我的是基于Dialog的工程,点击对话框上的某个按钮,弹出新的模态对话框,此时这个新模态对话框里面有个CTreeCtrl控件,这个CTreeCtrl控件我设置了CheckBox,但我想让里面的某项的CheckBox不显示,我用了SetItemState(hTempNewItem, INDEXTOSTATEIMAGEMASK(0), TVIS_STATEIMAGEMASK);但仍然有CheckBox存在..请问这么消除这个CheckBox..


hTempNewItem = m_wndRelationTree.InsertItem(tsKnowledgeDlg->m_wndTree.GetItemText(hItem), 1, 1, hNewItem);
m_wndRelationTree.SetItemState(hTempNewItem, INDEXTOSTATEIMAGEMASK(0), TVIS_STATEIMAGEMASK);//依然无效..
...全文
416 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
UU_Yang 2012-01-17
  • 打赏
  • 举报
回复
SetCheck和SetItemState无效的问题可以这样解决:
窗口初始化时设置tree的风格,注意下面两行都要的!

m_tree.ModifyStyle(TVS_CHECKBOXES, 0);
m_tree.ModifyStyle(0, TVS_CHECKBOXES);
青稞 2010-02-22
  • 打赏
  • 举报
回复
感觉是因为没有刷新的原因,我在OnInitDialog里面添加这个属的节点可以,但设置状态都不行..但我把代码考到按钮响应事件里面去,节点可以添加上,而且状态也可以设置了...但我就需要开始的时候做这些事情啊,怎么弄?
青稞 2010-02-21
  • 打赏
  • 举报
回复
没有人回答呢..
我发现只要设置了ImageList之后,CheckBox的设置就有效了..不设置不行啊..
还有,在主对话框中我自己继承了个CTreeCtrl,不设置ImageList也行..真是奇怪..
有谁知道这是为什么??
青稞 2010-02-21
  • 打赏
  • 举报
回复
谢谢楼上几位的关注
可问题是主对话框里面我也有这样个CTreeCtrl,怎么就可以呢??
oldmanzhao 2010-02-21
  • 打赏
  • 举报
回复
TVS_CHECKBOXES
Version 4.70. Enables check boxes for items in a tree-view control. A check box is displayed only if an image is associated with the item. When set to this style, the control effectively uses DrawFrameControl to create and set a state image list containing two images. State image 1 is the unchecked box and state image 2 is the checked box. Setting the state image to zero removes the check box altogether. For more information, see Working with state image indexes.
Version 5.80. Displays a check box even if no image is associated with the item.


Once a tree-view control is created with this style, the style cannot be removed. Instead, you must destroy the control and create a new one in its place. Destroying the tree-view control does not destroy the check box state image list. You must destroy it explicitly. Get the handle to the state image list by sending the tree-view control a TVM_GETIMAGELIST message. Then destroy the image list with ImageList_Destroy.


If you want to use this style, you must set the TVS_CHECKBOXES style with SetWindowLong after you create the treeview control, and before you populate the tree. Otherwise, the checkboxes might appear unchecked, depending on timing issues.


MSDN上好像是说5.80版本的没有图片关联也会显示CheckBox,不知道是不是这个原因。
eajum 2010-02-21
  • 打赏
  • 举报
回复
CTreeCtrl控件是有这方面的问题,建议楼主是用无模式的。
青稞 2010-02-21
  • 打赏
  • 举报
回复
可以的..我以前尝试过的..但现在莫名其妙不行了..而且我发现我通过SetCheck设置CheckBox选中后,依然都不能选中,真是奇怪啊..看起来就想节点都添加上去了,但设置状态这些貌似都没有效果呢?有谁知道是怎么回事啊?
oldmanzhao 2010-02-21
  • 打赏
  • 举报
回复
CTreeCtrl好像是不能单独设某个项CheckBox的,都是全体有效的。
青稞 2010-02-21
  • 打赏
  • 举报
回复
怎么没有人来回答阿..
另外,我设置CheckBox选中也无效..真是奇怪了..

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧