Populating .NET TableLayoutPanel cells programatically

By | August 13, 2013

A code snippet on how to populate a TableLayoutPanel cells with controls:

tableLayout.ColumnCount = stateMachine.States.Count + 1; // 1 for header with test cases

int columnIndex = 1; //leave 1 for header
foreach (var state in stateMachine.States)
{
    var view = new StateMachineStateView(state);
    view.Dock = DockStyle.Fill;
    tableLayout.Controls.Add(view, columnIndex, 0); // Add(Control control, int column, int row)
    columnIndex++;
}

Leave a Reply

Your email address will not be published.