Add a row to a TableLayoutPanel at runtime with a textbox in each cell of the row

Fabrizio Leoncini 0 Reputation points
2024-05-03T09:34:51.5066667+00:00

I've tried and tried to add a row to a TableLayoutPanel but I can't. Can anyone tell me a tutorial to do this?

Thank you

Fabrizio

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,755 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Jiachen Li-MSFT 32,851 Reputation points Microsoft Vendor
    2024-05-03T11:44:11.28+00:00

    Hi @Fabrizio Leoncini ,

    You can refer to the following code.

    Add a new row to the TableLayoutPanel, then loop through each column and add a TextBox to each cell

        Private Sub AddRowToTableLayoutPanel(tableLayoutPanel As TableLayoutPanel)
            tableLayoutPanel.RowCount += 1
            For colIndex As Integer = 0 To tableLayoutPanel.ColumnCount - 1
                Dim textBox As New TextBox()
                textBox.Dock = DockStyle.Fill
                tableLayoutPanel.Controls.Add(textBox, colIndex, tableLayoutPanel.RowCount - 1)
            Next
        End Sub
    
    

    Best Regards.

    Jiachen Li


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.