Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5983051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:10:29+00:00 2026-05-22T22:10:29+00:00

I generate controls for a TableLayoutPanel dynamically. I have a delete button in each

  • 0

I generate controls for a TableLayoutPanel dynamically. I have a delete button in each row. When I click that, that row has to be removed.

    Dim removeBtn As New Button
    AddHandler removeBtn.Click, AddressOf DeleteRow
    tlp.Controls.Add(removeBtn, 5, rowCount)

I have not shown the code to add text boxes which are similar to above. I can get the row number of the clicked button. Using this, how to remove all controls from this row.

Private Sub DeleteRow(ByVal sender As System.Object, ByVal e As System.EventArgs)
   Dim currentRow As Integer = CType(CType(sender, Button).Parent, TableLayoutPanel).GetRow(CType(sender, Button))
   'Using this currentRow, how to delete this Row
End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T22:10:30+00:00Added an answer on May 22, 2026 at 10:10 pm

    Basically you have to:

    • Get the list of controls from that row and delete them from the TLP
    • Remove the corresponding row style from the TLP
    • Set the new row index for every control in every row after the deleted one
    • Decrement the RowCount

    Here is the VB.NET code to do the same.

    Public Sub RemoveRow(ByRef panel As TableLayoutPanel, ByRef rowIndex As Integer)
    
        panel.RowStyles.RemoveAt(rowIndex)
        Dim columnIndex As Integer
        For columnIndex = 0 To panel.ColumnCount - 1
            Dim Control As Control = panel.GetControlFromPosition(columnIndex, rowIndex)
            panel.Controls.Remove(Control)
        Next
        Dim i As Integer
        For i = rowIndex + 1 To panel.RowCount - 1
            columnIndex = 0
            For columnIndex = 0 To panel.ColumnCount - 1
                Dim control As Control = panel.GetControlFromPosition(columnIndex, i)
                panel.SetRow(control, i - 1)
            Next
        Next
        panel.RowCount -= 1
    End Sub
    

    Here is a C# extension method that will do this for you.

    public static void RemoveRow(this TableLayoutPanel panel, int rowIndex)
    {
        panel.RowStyles.RemoveAt(rowIndex);
    
        for (int columnIndex = 0; columnIndex < panel.ColumnCount; columnIndex++)
        {
            var control = panel.GetControlFromPosition(columnIndex, rowIndex);
            panel.Controls.Remove(control);
        }
    
        for (int i = rowIndex + 1; i < panel.RowCount; i++)
        {
            for (int columnIndex = 0; columnIndex < panel.ColumnCount; columnIndex++)
            {
                var control = panel.GetControlFromPosition(columnIndex, i);
                panel.SetRow(control, i - 1);
            }
        }
    
        panel.RowCount--;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bunch of controls: When a user clicks the Generate button, a
I am using user controls (.ascx) that each generate their own specific client validation
How may one get information that was used to programatically generate asp controls? For
I have an ASP.net page which contains some controls. I generate this controls by
I'm trying to bind to a collection of controls I generate dynamically: <ItemsControl ItemsSource={Binding
I want to generate PDF from a PHP file that includes HTML controls like
Is it possible to use css with controls that generate ClientID and not regular
In my MFC project, I want to generate the labels dynamically. Eg: I have
I have a host application that controls various factory classes which produce implementations of
I have a task to generate user controls, I'm wondering if there's any guides

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.