开发者

How to programmatically scroll TreeView control?

开发者 https://www.devze.com 2023-01-08 19:21 出处:网络
Please advice how can I scroll a .NET TreeView Control programmatically. It doesn\'t imple开发者_如何学运维mented any public methods to scrolling.If you need to scroll to the node:

Please advice how can I scroll a .NET TreeView Control programmatically.

It doesn't imple开发者_如何学运维mented any public methods to scrolling.


If you need to scroll to the node:

TreeNode.EnsureVisible();


Try this:

treeView1.TopNode = treeView1.Nodes[500];

EDIT Maybe more suggestive :-)

    private void Form1_Load(object sender, EventArgs e)
    {
        for (int i = 0; i < 100; i++) {
            TreeNode node = treeView1.Nodes.Add(i.ToString());
            for (int j = 0; j < 10; j++) {
                node.Nodes.Add(j.ToString());
            }
        }
    }

    private void ScrollNode(TreeNode node) {
        treeView1.TopNode = node;
        treeView1.Refresh();
        System.Threading.Thread.Sleep(50);
        if (node.IsExpanded) {
            foreach (TreeNode subNode in node.Nodes)
                ScrollNode(subNode);
        }
    }

    private void button1_Click(object sender, EventArgs e)
    {
        treeView1.Focus();
        foreach (TreeNode node in treeView1.Nodes) {
            ScrollNode(node);
        }
    }


Just select and unselect the lowest item. That should do the trick.

0

精彩评论

暂无评论...
验证码 换一张
取 消