Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

check if treeview's treenode with a specified text exists

Status
Not open for further replies.

sgalmeida

Programmer
May 25, 2004
1
PT
greetings

how can i check if a treeview contains a treenode with a specified text? i'm trying with the Nodes.Contains() method but doesn't work.
I'm reading data from a database, and the data is categorized (ex cars, bikes, trucks, etc). what I want to do is to group on tree nodes the category of data and then display on child tree nodes the description of the items within the category. any ideas? If I use the treeview.Nodes.Contains(new TreeNode("cars")), it does not work.

TIA

Almeida
 
You can use something like this
Code:
bool checkNode(string s)
{
 for(int i=0;i<myTree.Nodes[0].Nodes.Count;i++)
 {
  if(myTree.Nodes[0].Nodes[i].Text==s) return true;
 }
 return false;
}
This asuming that you have a parent node who contains the data you want.
rootnode
-child1
-prop1
-prop2
-child2
...


________
George, M
Searches(faq333-4906),Carts(faq333-4911)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top