Tengo un TableLayoutPanel con 3 columnas y 1 fila: (botón, control de usuario eliminar, añadir el botón)¿Cómo añadir filas en medio de una TableLayoutPanel
Quiero el botón Añadir para añadir una nueva fila similar a lo anterior debajo del botón de clics: por ejemplo: ANTES:
- (botón 1 botón 1, control de usuario 2 Eliminar, Añadir)
- (botón 2, control de usuario 2 Eliminar, Añadir botón 2)
Después de hacer clic en "Añadir botón 1":
- (botón 1, Control de Usuario 2 Retire, el botón Agregar 1)
- (botón 3, Control de Usuario 3 Retire, el botón Agregar 3)
- (Quitar el botón 2, Control de usuario 2, botón Agregar 2)
Logré agregar la fila al final del panel de la mesa pero no al medio: sigue atornillando el diseño. He aquí un fragmento del controlador de eventos:
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);
}
esto no funciona correctamente.
¿Estoy haciendo algo mal? ¿alguna sugerencia?
+1 ¡Muchas gracias por compartir, Eldad! Tuve exactamente el mismo problema. Simplemente no tenía sentido por qué agregar elementos al principio y al final de la colección funcionó, pero falló en cualquier punto entre el inicio y el final ... SetChildIndex no solo eliminó muchos códigos, sino que también funciona como un encanto :) ¡thx otra vez! – libjup
Me alegro de haber podido ayudar :) – Eldad