.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> ASP.NET Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Search Tree view Recursively and check the checkbox of search item

Posted By:Hiren Soni       Posted Date: August 29, 2010    Points: 10    Category: ASP.NET Controls    URL: http://www.dotnetspark.com  

Search Tree view Recursively and check the checkbox of search item
 


Search the treeview based on search value and check that item if it is a searched value.


There is FindNode(searchval) method but it only finds with in level1 . it doesnâ?Tt find from the child nodes.



So here is code snippet for searching all the items of treeview.







protected void Button1_Click(object sender, EventArgs e)

{

//search item

string checkit = "item1";



// iterating all parent nodes of treeview.

foreach (TreeNode t in TreeView1.Nodes)

{

search_it(t, str);

}

}



protected void search_it(TreeNode t, string str)

{

if (t != null)

{

if (t.Value == str)

{

t.Checked = true;

}

else

{

// if node contains child node,then process it

foreach (TreeNode temp in t.ChildNodes)

{ search_it(temp, str);



}



}



}

else

{

return;

}



}

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend