Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to add rows into middle of a TableLayoutPanel
    primarykey
    data
    text
    <p>I have a TableLayoutPanel with 3 columns and 1 row: (Remove button, User Control, Add button)</p> <p>I want the Add button to add a new row similar to the above below the clicked button: e.g: BEFORE:</p> <ol> <li>(Remove button 1, User Control 2, Add button 1)</li> <li>(Remove button 2, User Control 2, Add button 2)</li> </ol> <p>After clicking"Add button 1":</p> <ol> <li>(Remove button 1, User Control 2, Add button 1)</li> <li>(Remove button 3, User Control 3, Add button 3)</li> <li>(Remove button 2, User Control 2, Add button 2)</li> </ol> <p>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:</p> <pre><code>void MySecondControl::buttonAdd_Click( System::Object^ sender, System::EventArgs^ e ) { int rowIndex = 1 + this-&gt;tableLayoutPanel-&gt;GetRow((Control^)sender); /* Remove button */ Button^ buttonRemove = gcnew Button(); buttonRemove-&gt;Text = "Remove"; buttonRemove-&gt;Click += gcnew System::EventHandler(this, &amp;MySecondControl::buttonRemove_Click); /* Add button */ Button^ buttonAdd = gcnew Button(); buttonAdd-&gt;Text = "Add"; buttonAdd-&gt;Click += gcnew System::EventHandler(this, &amp;MySecondControl::buttonAdd_Click); /*Custom user control */ MyControl^ myControl = gcnew MyControl(); /* Add the controls to the Panel. */ this-&gt;tableLayoutPanel-&gt;RowCount += 1; this-&gt;tableLayoutPanel-&gt;Controls-&gt;Add(buttonRemove, 0, rowIndex); this-&gt;tableLayoutPanel-&gt;Controls-&gt;Add(myControl, 1, rowIndex); this-&gt;tableLayoutPanel-&gt;Controls-&gt;Add(buttonAdd, 2, rowIndex); } </code></pre> <p>This doesn't work properly.</p> <p>Am I doing something wrong? any suggestions?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload