EDN Admin
Well-known member
Hello everyone. I am populating a TreeView with nodes and subnodes and ran into a problem that I just cannot figure out. So I figured I would ask how best I should approach this since the people on these forums are so knowledgeable...
First, I want to check to see if any of the nodes (Not subnodes) contains a particular value in its .Text property. In order to do this, do I need to parse all of the nodes? Im worried about performance...
I mean, I could do something like:
foreach(Node node in MyTreeView.Nodes)
if(node.Text != myString)
{
}
But I am worried about performance. Also, if using a foreach, wouldnt it add the node if the first node isnt a match, even if the second node might be? Also, when doing it this way I got an error that:
Collection was modified; enumeration operation may not execute.
My second question is relative to the subnodes. I am connecting to a database and pulling some records. How would be the best way to check to see if a value already existed as the .Text property of a subnode and remove it if it already exists?
Would I have to do a foreach subnode in foreach node to do this? Would I just end up getting the C# Collection was modified; enumeration operation may not execute. error doing this as well?
Thanks for the help,
Matt
View the full article
First, I want to check to see if any of the nodes (Not subnodes) contains a particular value in its .Text property. In order to do this, do I need to parse all of the nodes? Im worried about performance...
I mean, I could do something like:
foreach(Node node in MyTreeView.Nodes)
if(node.Text != myString)
{
}
But I am worried about performance. Also, if using a foreach, wouldnt it add the node if the first node isnt a match, even if the second node might be? Also, when doing it this way I got an error that:
Collection was modified; enumeration operation may not execute.
My second question is relative to the subnodes. I am connecting to a database and pulling some records. How would be the best way to check to see if a value already existed as the .Text property of a subnode and remove it if it already exists?
Would I have to do a foreach subnode in foreach node to do this? Would I just end up getting the C# Collection was modified; enumeration operation may not execute. error doing this as well?
Thanks for the help,
Matt
View the full article