0

i have used below code for filtering tree view, search function works correctly, but i do not know how to refresh tree view and populate that after clicking the button.

 private IEnumerable<TreeNode> FindNodeByValue(TreeNodeCollection nodes, string searchstring)
 {
foreach (TreeNode node in nodes)
 {
if (node.Value.IndexOf(searchstring,
      StringComparison.CurrentCultureIgnoreCase) >= 0)
    yield return node;
else
{
    foreach (var subNode in FindNodeByValue(node.ChildNodes, searchstring))
        yield return subNode;
}
 }

}

 protected void Button1_Click(object sender, EventArgs e) {

 var query= FindNodeByValue(TreeView1.Nodes, fieldFilterTxtBx.Text);
 if (query != null)
{
//TreeView1.Nodes[0].Expand();
//TreeView1.Nodes.Clear();
foreach (TreeNode node in query.ToList())
{
    TreeView1.Nodes.Add(node);

}


//  TreeNode newnode = new TreeNode("Detail Engineering");
// TreeView1.Nodes.Add(newnode);

TreeView1.ExpandAll();
}

else
{

Label1.Text = "No file found";

 }

 }`
2
Contributors
1
Reply
8
Views
4 Years
Discussion Span
Last Post by LastMitch
0

but i do not know how to refresh tree view and populate that after clicking the button.

You need to add a DataBind() to the TreeView1.Nodes

TreeView1.Nodes.DataBind();       
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.