recursion - C# Recursivly populate treeview from paths in registry -


question: how can recursivly populate treeview multiple path values strings registry treeview nodes using c#?

what do: recursivly populate treeview1 string values each registry value gathered in list[] array used listbox (listbox1) , ofcourse adding values registry not null . grateful or input problem.

how load path treeview1:

private void populatetreeview()         {             try             {                 treenode rootnode;                 nodeinfo ninfo;                  string path = global.getstartuppath();                 directoryinfo info = new directoryinfo(path);                 if (info.exists)                 {                     rootnode = new treenode(info.name, 3, 3);                     rootnode.name = info.name;                      ninfo = new nodeinfo(nodeinfo.types.root, info.fullname);                     rootnode.tag = ninfo;                      getdirectories(info, rootnode);                     treeview1.nodes.add(rootnode);                     treeview1.selectednode = rootnode;                 }              } 

how set path:

public static void setstartuppath(string path)         {             //open registry key             registrykey rk1 = registry.currentuser.opensubkey(@"software", true);             //create subkey, if not exist             registrykey sk1 = rk1.createsubkey(@"example\test\path");              sk1.setvalue("startuppath", path);              sk1.close();              _startuppath = path;         } 

and how it:

public static string getstartuppath()     {         if ( (_startuppath != null) && (_startuppath != string.empty) )                 return _startuppath;                    //check registry         else         {             //open registry key             registrykey rk1 = registry.currentuser.opensubkey(@"software\example\test\path", true);             if (rk1 == null)                 return string.empty;              _startuppath = (string)rk1.getvalue("startuppath");             rk1.close();             return _startuppath;         }       } 

(if helps) method getting paths in listbox:

public static string[] getpaths()         {             //open registry key             registrykey rk1 = registry.currentuser.opensubkey(@"software\example\test\path\list", true);             if (rk1 == null)                 return null;              string[] list = new string[rk1.valuecount];               (int = 0; < rk1.valuecount; i++)             {                 list[i] = rk1.getvalue(i.tostring()).tostring();             }             rk1.close();             return list;          } 

solved myself. others coming here looking answer how solved treeview.

        try         {             treenode rootnode;             nodeinfo ninfo;              string[] paths = global.getpaths();             (int = 0; < paths.length; i++)             {                 string path = paths[i];                 directoryinfo info = new directoryinfo(path);                 if (info.exists)                 {                     rootnode = new treenode(info.name, 3, 3);                     rootnode.name = info.name;                      ninfo = new nodeinfo(nodeinfo.types.root, info.fullname);                     rootnode.tag = ninfo;                      getdirectories(info, rootnode);                     treeview1.nodes.add(rootnode);                     treeview1.selectednode = rootnode;                 }             }          }          catch (exception ex)         {             //.....             logic.log.write("error populatetreeview -" + ex.message);         } 

Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -