Treeview basic question
-
Hello, I have 2 treeviews and one button. Ofter selecting a node in the first treeview and clicking the button, the selected node most be copied into the second treeview. Bud how can i check first whether the second treeview already contains the selected node in treeview1? Thanks, Priya
-
Hello, I have 2 treeviews and one button. Ofter selecting a node in the first treeview and clicking the button, the selected node most be copied into the second treeview. Bud how can i check first whether the second treeview already contains the selected node in treeview1? Thanks, Priya
Do you have a key or some kind of identifier that you're checking? Are you just checking the node text? Generally speaking, you can use recursion to check each tree node with a boolean value for whether the node exists.
-
Do you have a key or some kind of identifier that you're checking? Are you just checking the node text? Generally speaking, you can use recursion to check each tree node with a boolean value for whether the node exists.
-
something like this
bool ContainsNode(string nodeText, Node treeNode){
if(treeNode.Text.Equals(nodeText){
return true;
}bool contained = false;
foreach(Node node in treeNode.Children){
contained |= ContainsNode(nodeText, node);
}return contained;
} -
Hello, I have 2 treeviews and one button. Ofter selecting a node in the first treeview and clicking the button, the selected node most be copied into the second treeview. Bud how can i check first whether the second treeview already contains the selected node in treeview1? Thanks, Priya
Create a List of the node text for second treeview. On button click, check if the list contains the text. If yes do not add. If no add the text to list and a node in treeview. This will avoid looping through nodes for each and every time. However you will have to loop through for once to create the list.
The word "politics" describes the process so well: "Poli" in Latin meaning "many" and "tics" meaning "bloodsucking creatures." जय हिंद
-
Hello, I have 2 treeviews and one button. Ofter selecting a node in the first treeview and clicking the button, the selected node most be copied into the second treeview. Bud how can i check first whether the second treeview already contains the selected node in treeview1? Thanks, Priya
I often do it with LINQ. See this article http://www.codeproject.com/KB/cs/KingMark.aspx[^]