I have a TableLayoutPanel with 3 columns and 1 row: ("Delete" button, "User control", "Add")
I want the Add button to add a new line similar to the one below by pressing a button: for example: BEFORE:
- (Delete Button 1, User Control 2, Add Button 1)
- (Delete button 2, User control 2, Add button 2)
After clicking the "Add Button 1" button:
- (Delete Button 1, User Control 2, Add Button 1)
- (Delete button 3, User control 3, Add button 3)
- (Delete button 2, User control 2, Add button 2)
I managed to add a row to the end of the tablelayoupanel, but not to the middle: it continues to spin the layout. Here is an event handler fragment:
void MySecondControl::buttonAdd_Click( System::Object^ sender, System::EventArgs^ e )
{
int rowIndex = 1 + this->tableLayoutPanel->GetRow((Control^)sender);
Button^ buttonRemove = gcnew Button();
buttonRemove->Text = "Remove";
buttonRemove->Click += gcnew System::EventHandler(this, &MySecondControl::buttonRemove_Click);
Button^ buttonAdd = gcnew Button();
buttonAdd->Text = "Add";
buttonAdd->Click += gcnew System::EventHandler(this, &MySecondControl::buttonAdd_Click);
MyControl^ myControl = gcnew MyControl();
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 does not work properly.
Am I doing something wrong? any suggestions?