vb.net - unwanted treeview node duplicating at the end of list -


i have following code cant seem find reason (nor solution) why parent node keeps appearing @ end of list duplicate?

imports system.io public class form1  private sub form1_load(sender object, e eventargs) handles mybase.load     dim di new io.directoryinfo("c:\la")     dim diar1 io.fileinfo() = di.getfiles()     dim dra io.fileinfo      each dra in diar1          'dim sr streamreader = new streamreader(dra.fullname)         if system.io.path.getextension(dra.name).tolower() = ".xls"             treeview1.nodes.add("offerts")             treeview1.nodes(0).nodes.add(dra.name)         end if     next  end sub end class 

on first .xls file finds, creates "offerts" node in root of tree, , creates node filename under "offerts".

on subsequent .xls files, creates another "offerts" node in root, , creates node filename under first node (the first "offerts" node created).

so think want create "offerts" node once, @ root, treeview1.nodes.add("offerts") should not run each time finds .xls file. replacing line like:

if treeview1.nodes.count = 0 treeview1.nodes.add("offerts") 

will work, given scenario. if treeview has nodes, you'll have modify logic.


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -