我做的是树控件的多选功能,在多选过程中,需要给新点击的项设置focus,只有下面这种情况,能保留多选的高亮
CTreeCtrl::SelectItem(hItem);
CTreeCtrl::SetItemState(hFocus, TVIS_SELECTED, TVIS_SELECTED);
CTreeCtrl::SelectItem(hItem);
其中hFocus是当前选中的item,hItem是要选中的item
这种情况实现的多选,在按住Ctrl取消之前的选择时,会消除之前这一项和他上一次选中项的高亮!目前的问题就是这个,求高人指点啊。
多选我参考的方案原代码是
CTreeCtrl::SelectItem(NULL); //will cause notify, but can be taken as focus change
CTreeCtrl::SetItemState(hFocus, TVIS_SELECTED, TVIS_SELECTED);
CTreeCtrl::SelectItem(hItem); //set focus (will consequently select, if not already focused)
这种在他的原解决方案里能实现多选效果,而且没问题,但是拿出来我用,就实现不了,他是用单文档实现的,我需要在mfc窗口中实现!
最后选了个折中的方法,多选时不去控制焦点,仍放到第一个选择的项上,单选时从新设置焦点
树没有办法多选(高亮)
除非你重绘,不过更好的办法是给tree加上checkbox
http://blog.csdn.net/headmaster110/article/details/5097972
http://www.2cto.com/kf/201310/250317.html
可以考虑自绘, 自己控制
他的第一句CTreeCtrl::SelectItem(NULL); 先取消选中