c# - TableLayoutPanel: Delete Rows -
i have tablelayoutpanel filled rows @ runtime using text file (get each row text file, , put in cells contained in new rows). code looks this:
public static string urllist= @"c:\users\berisha\desktop\urls.txt"; string[] urlrows = system.io.file.readalllines(@urllist); private void initpaths() { int = 0; int c = 1; while (a < urlrows.length-1) { //new label var label = new label(); label.dock = dockstyle.fill; label.autosize = false; label.text = urlrows[a]; label.textalign = system.drawing.contentalignment.middleleft; label.size = new system.drawing.size(22, 13); label.backcolor = system.drawing.color.transparent; tbp.controls.add(label, 3, c); //add tablelayoutpanel a++; c++; } }
although want able manually edit source, wrote method delete new created, seem stuck here, because doesn't work:
private void clearpaths() { int c = urlrows.length - 1; while (c <= urlrows.length - 1) { tbp.rowstyles.removeat(c); //remove tablelayoutpanel c--; } }
//the code stops at: tablelayoutpanel.rowstyles.removeat(c);(while debugging) //and error reads : "object reference not set instance of object" update: managed out of error, problem now, after removeat, nothing seems removed know do?
i googled , binged solution problem days , couldn't find one. came solution works!
tablelayoutpanel.suspendlayout(); while (tablelayoutpanel.rowcount > 1) { int row = tablelayoutpanel.rowcount - 1; (int = 0; < tablelayoutpanel.columncount; i++) { control c = tablelayoutpanel.getcontrolfromposition(i, row); tablelayoutpanel.controls.remove(c); c.dispose(); } tablelayoutpanel.rowstyles.removeat(row); tablelayoutpanel.rowcount--; } tablelayoutpanel.resumelayout(false); tablelayoutpanel.performlayout();
in solution, not want remove first row.