Ok the problem seems to be a little bit more complicated than I thought at
first sight.
Solution, what to do when removing a row:
- decrement tableLayoutPanel.RowCount
- remove rowstyle: tableLayoutPanel.RowStyles.RemoveAt(...)
- remove corresponding controls of removed row in tabelLayoutPanel.Controls
- change RowCounter of controls that come after the removed row
Explanation of last action:
tableLayout.GetRow('control'), where 'control' is a control belonging to a
row that comes after the remove row, will give you his old rowIndex!
For that you need to set the new rowIndex for all controls belonging to a
row that's coming after a removed row.
My code:
for (int counter = controlsCounter; counter <
ux_tlpCostCenters.Controls.Count; counter++)
{
ux_tlpCostCenters.SetRow(ux_tlpCostCenters.Control s[counter],
ux_tlpCostCenters.GetRow(ux_tlpCostCenters.Control s[counter]) - 1);
}
Over here the integer 'controlsCounter' is the beginindex of the first
control in my tableLayoutPanel.Controls that needs a new RowIndex.
This should really help now ;-)
"avanti" wrote:
Hi,
I am trying to delete rows from a TableLayoutPanel at Runtime. I tried
editing the RowStyles collection but doesn't do what I want it to. I
have a table with 10 rows. I want to delete rows 2 to 10 at runtime,
keeping the first row unchanged.
Can this be done?
Thanks,
Avanti Ketkar