如何在MFC树视图中选择多个项目? [英] How do i select multiple items in MFC treeview?
问题描述
目前,当我尝试在树形视图(MFC)中执行多项选择时,它允许我在任何时间点选择最多2项。
下面是一个例子
如果Tree有以下项目
Root
-1
-2
-3
-4
-5
我做鼠标左键单击项目1上的+ ctrl键(选中它)
用ctrl键单击项目2向下(选中)
按住ctrl键单击项目3(选择项目3,但取消选择项目1)
单击项目4,按住ctrl键(选择项目4,但取消选择项目2)。
因此,如果您观察到,在任何时间点,只有2个项目将被选中或在树中突出显示。我将代码迁移到visual studio 2010后观察到这个问题。请建议是否需要更正。
当我从树中选择一个新项目时,我使用GetSelectedItem()方法获取上一项并使用 SetItemState方法将状态设置回TVIS_SELECTED。
必须以编程方式实现多项选择。 请参阅
树视图控件扩展样式表示TVS_EX_MULTISELECT为"不支持"。不要使用。"
您可以找到
https://www.codeproject.com/Articles/8006/Multi-select-Treeview-control-v 非常有用。
Hi,
Currently when i try to perform multiple selection in treeview (MFC), it lets me select max 2 items at any point of time.
Below is an example
If Tree has below items
Root
-1
-2
-3
-4
-5
I do a mouse left click + ctrl key on item 1 (it is selected)
Click on item 2 with ctrl key down (it is selected)
Click on item 3 with ctrl key down (item 3 selected, but item 1 is deselected)
Click on item 4 with ctrl key down (item 4 is selected, but item 2 is deselected).
So if you observe, at any point of time only 2 items will be selected or highlighted in tree. I observe this issue after migrating my code to visual studio 2010. Please suggest if any corrections required.
When i select a new item from the tree, i use GetSelectedItem() method to get previous item and set the state back to TVIS_SELECTED using SetItemState method.
Multiple selection must be implemented programatically. See Tree-View Control Extended Styles which indicates TVS_EX_MULTISELECT as "Not supported. Do not use."
You may find https://www.codeproject.com/Articles/8006/Multi-select-Treeview-control-v helpful.
这篇关于如何在MFC树视图中选择多个项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!