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 6773435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:40:05+00:00 2026-05-26T15:40:05+00:00

I have a TableLayoutPanel with 3 columns and 1 row: (Remove button, User Control,

  • 0

I have a TableLayoutPanel with 3 columns and 1 row:
(Remove button, User Control, Add button)

I want the Add button to add a new row similar to the above below the clicked button:
e.g:
BEFORE:

  1. (Remove button 1, User Control 2, Add button 1)
  2. (Remove button 2, User Control 2, Add button 2)

After clicking”Add button 1″:

  1. (Remove button 1, User Control 2, Add button 1)
  2. (Remove button 3, User Control 3, Add button 3)
  3. (Remove button 2, User Control 2, Add button 2)

I managed to add the row to the end of the tablelayoupanel but not to the middle: It keeps screwing up the layout.
Here’s a snippet of the event handler:

void MySecondControl::buttonAdd_Click( System::Object^ sender, System::EventArgs^ e )
{
   int rowIndex = 1 + this->tableLayoutPanel->GetRow((Control^)sender);

   /* Remove button */
   Button^ buttonRemove = gcnew Button();
   buttonRemove->Text = "Remove";
   buttonRemove->Click += gcnew System::EventHandler(this, &MySecondControl::buttonRemove_Click);

   /* Add button */
   Button^ buttonAdd = gcnew Button();
   buttonAdd->Text = "Add";
   buttonAdd->Click += gcnew System::EventHandler(this, &MySecondControl::buttonAdd_Click);

   /*Custom user control */
   MyControl^ myControl = gcnew MyControl();

   /* Add the controls to the Panel. */
   this->tableLayoutPanel->RowCount += 1;
   this->tableLayoutPanel->Controls->Add(buttonRemove, 0, rowIndex);
   this->tableLayoutPanel->Controls->Add(myControl, 1, rowIndex);
   this->tableLayoutPanel->Controls->Add(buttonAdd, 2, rowIndex);
}

This doesn’t work properly.

Am I doing something wrong? any suggestions?

  • 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-26T15:40:05+00:00Added an answer on May 26, 2026 at 3:40 pm

    Finally found a solution: Instead of adding the controls to thier direct location, I’m adding them to the end and then use the SetChildIndex() function to move the control to the desired location:

    void MySecondControl::buttonAdd_Click( System::Object^ sender, System::EventArgs^ e )
    {
       int childIndex = 1 + this->tableLayoutPanel->Controls->GetChildIndex((Control^)sender);
    
       /* Remove button */
       Button^ buttonRemove = gcnew Button();
       buttonRemove->Text = "Remove";
       buttonRemove->Click += gcnew System::EventHandler(this, &MySecondControl::buttonRemove_Click);
    
       /* Add button */
       Button^ buttonAdd = gcnew Button();
       buttonAdd->Text = "Add";
       buttonAdd->Click += gcnew System::EventHandler(this, &MySecondControl::buttonAdd_Click);
    
       /*Custom user control */
       MyControl^ myControl = gcnew MyControl();
    
       /* Add the controls to the Panel. */
       this->tableLayoutPanel->Controls->Add(buttonRemove);
       this->tableLayoutPanel->Controls->Add(myControl);
       this->tableLayoutPanel->Controls->Add(buttonAdd);
    
       /* Move the controls to the desired location */
       this->tableLayoutPanel->Controls->SetChildIndex(buttonRemove, childIndex);
       this->tableLayoutPanel->Controls->SetChildIndex(myControl, childIndex + 1);
       this->tableLayoutPanel->Controls->SetChildIndex(buttonAdd, childIndex + 2);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a TableLayoutPanel to which I add rows dynamically. Each row has an
I'm attempting to dynamically add both columns and rows to a TableLayoutPanel. I have
I have a user control that contains a 2-column TableLayoutPanel and accepts commands to
I have a tablelayoutpanel. 2x2 - 2 columns 2 rows. For example, I added
Stack-O, I have a TableLayoutPanel with 50 rows and 6 columns. That's all well
I have a TableLayoutPanel that contains rows of labels. This control lives on form
I want to have another copy of some control upon dragging and dropping it
I have a tableLayoutPanel with either 5 or 7 columns. Users can click show/hide
I have a TableLayoutPanel control that is initially empty - 0 rows and 0
I generate controls for a TableLayoutPanel dynamically. I have a delete button in each

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.