Monday, August 4, 2014

How can i make in treeView1 in TreeNode EnsureVisible() that it will show the top first child node and not the bottom as first ?

In this method i'm doing a search in a 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.



No comments:

Post a Comment