c# - Remove a checkbox that is being created dynamically in a loop -


i have bunch of code dynamicly creates controls. looks in folder , lists filenames in it. each file in folder creates checklistbox item, listbox item , 2 checkboxes. working great , intended:

 private void getallfiles(string type)     {         try         {             string listpath = "not_defined";              if (type == "internal_mod")             {                 int first_line = 76;                 int next_line = 0;                 int = 0;                 checkbox[] chkmod = new checkbox[100];                 checkbox[] chktool = new checkbox[100];                 listpath = this.internalmodspath.text;                 string[] filestolist = system.io.directory.getfiles(listpath);                 foreach (string file in filestolist)                 {                          if (!internalmodschklist.items.contains(file))                     {                         internalmodschklist.items.add(file, false);                         string filename = path.getfilename(file);                         internalmodnamelist.items.add(filename);                          //-----------------                         // draw checkboxes                         //-----------------                         chkmod[i] = new checkbox();                                                 chktool[i] = new checkbox();                         chkmod[i].name = "modchk" + i.tostring();                                   chktool[i].name = "modchk" + i.tostring();                         //chkmod[i].tabindex = i;                                                   //chktool[i].tabindex = i;                         chkmod[i].anchor = (anchorstyles.left | anchorstyles.top);                  chktool[i].anchor = (anchorstyles.left | anchorstyles.top);                         chkmod[i].checked = true;                                                   chktool[i].checked = false;                         chkmod[i].autocheck = true;                                                 chktool[i].autocheck = true;                         chkmod[i].bounds = new rectangle(549, first_line + next_line, 15, 15);      chktool[i].bounds = new rectangle(606, first_line + next_line, 15, 15);                          groupbox7.controls.add(chkmod[i]);                                          groupbox7.controls.add(chktool[i]);                         //-----------------                          next_line += 15;                         i++;                     }                 }             } 

now problem want user able delete these thing again based on checklistbox' checked items.. have no problems deleting items in checklistbox or items in listbox, want remove 2 checkboxes create ..

this got remove items in checklistbox, , listbox

private void internalmodlistdel_btn_click(object sender, eventargs e)     {         int count = internalmodschklist.items.count;         (int index = count; index > 0; index--)         {             if (internalmodschklist.checkeditems.contains(internalmodschklist.items[index - 1]))             {                 internalmodschklist.items.removeat(index - 1);                 internalmodnamelist.items.removeat(index - 1);                 groupbox7.controls.remove(modchk[index - 1]);             }          }       } 

as can see have tried write remove checkbox doesn't work , have no idea how make work

can assist ?

try using usercontrols. use listbox controller show usercontrols, user control can built checkboxes, , labels want .

another suggestion bind list observablecollection contain usercontorols have created.

this way, more simlpe add/remove/change items inside.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -