将焦点设置为Treeview中新添加的节点 [英] Setting focus to newly added nodes in treeview

查看:146
本文介绍了将焦点设置为Treeview中新添加的节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我将新节点添加到treeview的现有节点(这是父节点)中.新添加的节点将位于父节点下.我想将焦点放在新添加的节点上,而不是在该父节点上.

谁能帮我.

在此先感谢您

Hi,

I am adding new nodes to the already existing nodes(this is parent) of treeview. The newly added nodes will be under the parent. I want to set the focus on the newly added node, but not on that parent.

Can anyone assist me.

Thanks in advance

推荐答案

您可能会感到困惑,因为您混淆了两个不同的概念:聚焦选择.

聚焦"意味着获得键盘焦点,仅此而已;显示焦点的视觉线索只是它的一个方面.通常,整个控件是集中的(我这里不考虑复合控件,它们可以具有子控件,并且只能集中一个基本"控件).

TreeView控件是只能作为整体控件集中的控件.可以选择其节点.请注意,无论控件是否处于焦点状态,节点都保持选中状态.您可能会争辩:在就地编辑节点文本期间会发生什么?看起来节点是集中的."不,节点永远不会集中精力.实际上,当发生就地版本时,整个树视图都会失去其焦点,因为在树节点的位置创建了一个单独的就地文本编辑器,并暂时抓住了焦点.

您可以使用属性System.Windows.Forms.TreeView.SelectedNode获取或设置选定的节点,请参见 http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.aspx [ http://msdn.microsoft.com/en-us/library/system.windows.forms.control.canselect.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.fullrowselect.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.hideselection.aspx [ ^ ].

您很可能还需要更改选择时引发的事件:
http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.onafterselect.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.onbeforeselect.aspx [ ^ ].

基本上,这就是全部.

—SA
You might be confused because you mix up two different concepts: focusing and selection.

"Focusing" means getting keyboard focus, nothing else; showing of a visual clue of the focus is just one aspect of it. Normally the whole control is focused (I don''t consider composite controls here, they can have children controls and only one of the "elementary" controls can be focused).

The TreeView control is the control which can be focused only as a whole control. Its nodes can be selected. Note that the nodes remain selected when the control is focused or not. You might argue: "What happens during in-place editing of the node text? It looks like the node is focused." No, node is never focused. Actually, when an in-place edition happens, whole tree view looses its focus, because a separate in-place text editor is created at the location of a tree node and temporarily grabs the focus.

You can get or set selected node using the property System.Windows.Forms.TreeView.SelectedNode, see http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.aspx[^].

See also the property affecting selection and presentation of selection:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.canselect.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.fullrowselect.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.hideselection.aspx[^].

Most likely you will also need events raised on change in selection:
http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.onafterselect.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.onbeforeselect.aspx[^].

Basically, that''s all what involved.

—SA


尝试类似的帖子

将新项目添加到树中查看并保持树视图打开到正确的位置 [
Try this similar post

Adding New Items to a Tree View and keeping the Tree View Open to the right position[^]


这篇关于将焦点设置为Treeview中新添加的节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆