TableLayoutPanel.RowCount doesn't seem to add new rows (similarly for TableLayoutPanel.ColumnCount
- Dominant language
- C#
- Stars
- 4.9k
- Forks
- 1.1k
- Avg merge
- 20h 23m
- Merged PRs (30d)
- 103
Description
* .NET Core Version:
3.1.301
* Have you experienced this same bug with .NET Framework?:
Yes, this was made in .Net Framework 4.7.2 (according to project information).
**Problem description:**
The following is my class. It's straightforward and just contains a table. The table is 6x6 in the Designer (for testing).
`Table` here is a `TableLayoutPanel`.
```c#
public partial class Board : UserControl
{
public int BoardSize { get; private set; }
public Board(int size)
{
InitializeComponent();
BoardSize = size;
Table.RowCount = size;
Table.ColumnCount = size;
float val = 100 / size;
for (int i = 0; i < size; i++)
{
Table.RowStyles[i].Height = val; // exception raised here
Table.ColumnStyles[i].Width = val;
for (int j = 0; j < size; j++)
{
Table.SetCellPosition(new Button(), new TableLayoutPanelCellPosition(i, j));
}
}
// Table.CellPaint += Table_CellPaint;
}
```
Error:
> System.ArgumentOutOfRangeException: 'Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index'
It turns out, the error occurs when it tries to reach index 6 (which is basically the RowCount in the Designer).
I'm not sure why this is occurring, as I just set new values for the RowCount and ColumnCount a few lines before.
**Expected behavior:**
Index should not be out of range for Table.RowStyles[i] when it's less than Table.RowCount.
**Minimal repro:**
Not sure what "repro" means...
Contributor guide
Assessment
This issue has not been assessed yet.