c# - I can't add Treenode in Treeview -


i add tree node parent form though child form not appear on treeview

and add treeview imageindex

please let me know how add treenode

// [childform] private void button1_click(object sender, eventargs e) {    main _main = new main();    _main.setftpclient(); }  //[mainform] private void toolstripbutton1_click(object sender, eventargs e) {    _connectform.startposition = formstartposition.centerparent;    _connectform.showdialog(this); }  public void setftpclient() {    treenode svrnode = new treenode("server", 0, 0);    svrnode.nodes.add("se", "seoul", 0, 0);    svrnode.nodes.add("dj", "seoul1", 0, 0);    svrnode.nodes.add("bs", "seoul2", 0, 0);     treenode netnode = new treenode("network", 1, 1);    netnode.nodes.add("t1", "cable", 1, 1);    netnode.nodes.add("56k", "modem", 1, 1);    netnode.nodes.add("3g", "wireless", 1, 1);    tv_ftp.nodes.add(svrnode);    tv_ftp.nodes.add(netnode); } 

there many ways this. 1 way having reference of main form in child form. add parameter in child form constructor. let's child form's name connectform , main form mainform.

using system; using system.windows.forms;  namespace treeviewdemo {     public partial class connectform : form     {         form parent; // reference of main form          public connectform(form form)         {             initializecomponent();              // set reference of main form             parent = form;         }          void button1click(object sender, eventargs e)         {             // have cast mainform first,             // otherwise method setftpclient not accessible             var _main = (mainform) parent;             _main.setftpclient();         }     } } 

then pass main form child form using parameterized constructor.

using system; using system.windows.forms;  namespace treeviewdemo {     public partial class mainform : form     {         public mainform()         {             initializecomponent();         }          void button1click(object sender, eventargs e)         {             // create instance of child form, , pass main form             var _connectform = new connectform(this);              _connectform.startposition = formstartposition.centerparent;             _connectform.showdialog(this);         }          public void setftpclient()         {             treenode svrnode = new treenode("server", 0, 0);             svrnode.nodes.add("se", "seoul", 0, 0);             svrnode.nodes.add("dj", "seoul1", 0, 0);             svrnode.nodes.add("bs", "seoul2", 0, 0);              treenode netnode = new treenode("network", 1, 1);             netnode.nodes.add("t1", "cable", 1, 1);             netnode.nodes.add("56k", "modem", 1, 1);             netnode.nodes.add("3g", "wireless", 1, 1);             tv_ftp.nodes.add(svrnode);             tv_ftp.nodes.add(netnode);         }     } } 

Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -