TableLayoutPanel.RowCount doesn't seem to add new rows (similarly for TableLayoutPanel.ColumnCount
#3 578 ouverte le 14 juil. 2020
Métriques du dépôt
- Stars
- (4 100 stars)
- Métriques de merge PR
- (Merge moyen 14j 22h) (56 PRs mergées en 30 j)
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.
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...