.NETView中的TreeView双击行为#

时间:2021-10-02 15:51:20

I have a regular .NET Windows Forms treeview control. The nodes are setup like this:

我有一个常规的.NET Windows窗体树视图控件。节点设置如下:

Group

---child

---child

If I double-click a collapsed Group node, it expands (as you'd expect) and the NodeMouseDoubleClick event is fired off, where my code does something if the selected node is NOT a group node.

如果我双击折叠的组节点,它会展开(如您所料)并触发NodeMouseDoubleClick事件,如果所选节点不是组节点,我的代码会执行某些操作。

The problem arises when the Group is located near the bottom of the treeview, so that when I double-click the Group node it would require the treeview to expand vertically to fit the child nodes into view. In such cases, if I double-click the Group node, by the time it expands and adjusts the treeview, my mouse cursor is over a child node (it had to push everything up), and that causes the NodeMouseDoubleClick to think the child node is selected, which causes very odd behaviour.

当组位于树视图的底部附近时会出现问题,因此当我双击组节点时,它将需要树视图垂直扩展以使子节点适合视图。在这种情况下,如果我双击组节点,当它扩展并调整树视图时,我的鼠标光标位于子节点上(它必须将所有内容都推到一起),这会导致NodeMouseDoubleClick认为子节点被选中,这会导致非常奇怪的行为。

How can I get around this? Should I not be using NodeMouseDoubleClick or..?

我怎么能绕过这个?我不应该使用NodeMouseDoubleClick或..?

I see it was also explained in the feedback report Problem with TreeView DoubleClick event after expanding/collapsing caused change of scroll.

我看到它也在反馈报告中解释了扩展/折叠导致滚动更改后TreeView DoubleClick事件的问题。

2 个解决方案

#1


15  

The NodeDoubleClick is fine, but instead of using the e.Node, use this.treeView1.SelectedNode.

NodeDoubleClick很好,但不使用e.Node,而是使用this.treeView1.SelectedNode。

#2


7  

Double-clicking a TreeNode is a mouse gesture that is already "used" by the TreeView to collapse/expand nodes Microsoft doesn't push the UI standards as much as Apple does, and on some level it is disappointing that Microsoft has exposed NodeDoubleClick, because they are encouraging you to amend the TreeView with your own custom behavior. This can be misleading to end users, who expect common behavior from common controls.

双击TreeNode是一个鼠标手势,TreeView已经“使用”它来折叠/扩展节点微软并没有像苹果那样推动UI标准,而且在某种程度上微软暴露了NodeDoubleClick令人失望,因为他们鼓励您使用自己的自定义行为修改TreeView。这可能会误导最终用户,他们期望共同控制的共同行为。

From Designing the User Interface by Ben Shneiderman, the first of Eight Golden Rules of Interface Design:

从Ben Shneiderman设计用户界面开始,八个黄金界面设计规则中的第一个:

  1. Strive for consistency.
  2. 力求一致性。

Consistent sequences of actions should be required in similar situations; identical terminology should be used in prompts, menus, and help screens; and consistent commands should be employed throughout.

在类似情况下应该要求采取一致的行动顺序;在提示,菜单和帮助屏幕中应使用相同的术语;应始终采用一致的命令。

Long story short, maybe you should not be using NodeMouseDoubleClick.

长话短说,也许你不应该使用NodeMouseDoubleClick。

#1


15  

The NodeDoubleClick is fine, but instead of using the e.Node, use this.treeView1.SelectedNode.

NodeDoubleClick很好,但不使用e.Node,而是使用this.treeView1.SelectedNode。

#2


7  

Double-clicking a TreeNode is a mouse gesture that is already "used" by the TreeView to collapse/expand nodes Microsoft doesn't push the UI standards as much as Apple does, and on some level it is disappointing that Microsoft has exposed NodeDoubleClick, because they are encouraging you to amend the TreeView with your own custom behavior. This can be misleading to end users, who expect common behavior from common controls.

双击TreeNode是一个鼠标手势,TreeView已经“使用”它来折叠/扩展节点微软并没有像苹果那样推动UI标准,而且在某种程度上微软暴露了NodeDoubleClick令人失望,因为他们鼓励您使用自己的自定义行为修改TreeView。这可能会误导最终用户,他们期望共同控制的共同行为。

From Designing the User Interface by Ben Shneiderman, the first of Eight Golden Rules of Interface Design:

从Ben Shneiderman设计用户界面开始,八个黄金界面设计规则中的第一个:

  1. Strive for consistency.
  2. 力求一致性。

Consistent sequences of actions should be required in similar situations; identical terminology should be used in prompts, menus, and help screens; and consistent commands should be employed throughout.

在类似情况下应该要求采取一致的行动顺序;在提示,菜单和帮助屏幕中应使用相同的术语;应始终采用一致的命令。

Long story short, maybe you should not be using NodeMouseDoubleClick.

长话短说,也许你不应该使用NodeMouseDoubleClick。