保持树形的滚动位置 [英] Maintain scroll position of treeview

查看:171
本文介绍了保持树形的滚动位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何能保持在.NET应用程序中的TreeView控件的滚动位置?例如,我有一个TreeView控件并通过添加不同的节点,以它的过程套结它们的底部。在这个过程中,我可以通过树状滚动查看不同的节点。问题是,当这个过程完成后,树形视图滚动到最底部。

看来,调用treenode.Expand()就是在这里扔我偏离了轨道。当父节点展开,它得到了焦点。

有没有解决的办法吗?如果我期待在一个特定的节点,而该进程正在运行,我不希望它在我跳舞,当这个过程就完成了。

解决方案

我想我想通了:

  1. 获取该节点在树视图顶部。
  2. 展开父节点。
  3. 请说是previously顶部可见的节点。

 如果treeNodeParent.IsExpanded = false,那么
    昏暗currentNode作为树节点= TreeViewHosts.GetNodeAt(0,0)
    treeNodeParent.Expand()
    currentNode.EnsureVisible()
结束如果
 

是一个更好的方式来做到这一点?

How can I maintain the scroll position of a treeview control in .NET application? For example, I have a treeview control and go through a process of adding various nodes to it tacking them on to the bottom. During this process, I can scroll through the treeview and view different nodes. The problem is when the process completes, the treeview scrolls to the very bottom.

It appears that calling treenode.Expand() is what is throwing me off track here. When a parent node is expanded, it gets the focus.

Is there a way around this? If I'm looking at a specific node while the process is running, I don't want it to jump around on me when the process is done.

解决方案

I think I figured it out:

  1. Get the node at the top of the treeview.
  2. Expand the parent node.
  3. Make the node that was previously at the top visible.

If treeNodeParent.IsExpanded = False Then
    Dim currentNode As TreeNode = TreeViewHosts.GetNodeAt(0, 0)
    treeNodeParent.Expand()
    currentNode.EnsureVisible()
End If

Is the a better way to do this?

这篇关于保持树形的滚动位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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