-1

In this method i'm doing a search in TreeNodes:

private void FindByText()
        {
            TreeNodeCollection nodes = treeView1.Nodes;
            foreach (TreeNode n in nodes)
            {
                FindRecursive(n);
            }
        }

And the FindRecursive:

private void FindRecursive(TreeNode treeNode)
        {
            foreach (TreeNode tn in treeNode.Nodes)
            {
                string result = Regex.Replace(tn.Text, @"^\d*\.\s*", string.Empty);
                if (tn.Text.Contains(this.txtNodeTextSearch.Text))
                {
                    tn.BackColor = Color.Yellow;
                    tn.EnsureVisible();
                    count++;
                    label11.Text = count.ToString();
                }

                FindRecursive(tn);
            }
        }

In the FindRecursive method i did:

tn.EnsureVisible();

But if for example i searched and it found 20 items it will scroll down and show me the last found item. Then i will need to scorll up to see the other items it found.

I need that it will make like tn.EnsureVisible(); but will point on the top first item and if i will like i will scroll down to see the others.

1 Answers1

0

I hope I get your point. You will need to "sort" your code the other way around, such that the "top" item ist the last one marked and focussed on with EnsureVisible(). So first put the recursion call right before your compare->EnsureVisible. This will cause the child items marked before the current top node gets checked and (possibly) marked visbile and focussed on. Then, if required, reverse the TreeNode Collection you loop through - it might be possible like this Why does IList<>.Reverse() not work like List<>().Reverse. So them the First Top Item will be checked last.

Community
  • 1
  • 1
Sebastian
  • 379
  • 1
  • 7