vb.net - How to search multiple treeview nodes at a particular depth -


please know how can search text of multiple treeview nodes @ particular depth on click of button? treeview nodes arranged follows:

enter image description here

i want prevent user entering duplicate grandchild nodes of same title treeview, i.e entering 'movie 2' second time should throw message movie 2 has been entered; if not, add new movie title.

the grandchild node titles fed treeview textbox. using visual basic 2010 express. thank in advance.

the code using is:

private sub button11_click(sender system.object, e system.eventargs) handles button11.click              'new movie title has been introduced study          dim selectednode treenode          selectednode = treeview1.selectednode            'to avoid entering duplicate movies title          dim newmoviename string = textbox1.text.trim.tolower ' content of node          dim parentnode = selectednode.parent ' parent          dim childnodes treenodecollection = parentnode.nodes ' children           dim wehaveduplicate boolean = false ' use flag if duplicate found.  set false.            each tempnode treenode in childnodes              'test have same name not referring same node              if tempnode.text.trim.tolower = newmoviename , tempnode isnot parentnode wehaveduplicate = true          next            if wehaveduplicate = true              'send message user              msgbox(textbox1.text & " parameter has been considered.", vbokonly)              exit sub          else              parentnode.nodes.add(textbox1.text)              treeview1.expandall()          end if          exit sub        end sub

all appreciated. thank you.

here little snippet use frequently. find node it's text. highlight , expand node found.

notice recursive, search bottom of supplied node collection (param). if supplied collection root node, search whole tree.

i apply unique string node.tag property. if adjust function that, can have duplicate text displaying while still having unique string for...

''' <summary> ''' find , expand node in tree view ''' </summary> private function findnode(byval searchtext string, byval nodestosearch treenodecollection, byval treetosearch treeview) treenode     dim returnnode treenode = nothing     try         each node treenode in nodestosearch             if string.compare(node.text, searchtext, true) = 0                 treetosearch.selectednode = node                 node.expand()                 returnnode = node                 exit             end if             if returnnode nothing returnnode = findnode(searchtext, node.nodes, treetosearch)         next     catch ex exception         throw     end try     return returnnode end function 

edited:
per recent comment,
might try using this...

wehaveduplicate = (findnode("movie 2", treeview1.nodes, treeview1) nothing) if wehaveduplicate = true   'message user of dupe else   'add movie end if 

Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -