How to add row and columns dynamically in a Tablelayoutpring C#?

Asked

Viewed 745 times

0

I have a TableLayoutPanel displayed in grid form on the screen that already has an X amount of rows and columns, and also contains components in its cells.
I allow, through a screen, the user to change the number of rows and columns of the TableLayoutPanel in order to provide new cells on the grid for the user to drag new components to the screen.
I have found solutions that allow me to create what I want, as long as I already add a new component to the created row or column, in case I don’t want to. The code snippet below shows the type of situation I found and does not serve me:

this.tableLayoutPanel1.RowStyles.Add(new RowStyle());

//para adicionar, neste caso, uma nova linha devo passar algum 
//componente para ser colocado na célula. Quero apenas criar uma
//célula vazio
this.tableLayoutPanel1.Controls.Add(new Componente(), coluna, novaLinha);

Does anyone have any idea how to do that?

  • What’s wrong with doing this.tableLayoutPanel1.Controls.Add(new Control(), coluna, novaLinha);?

  • The problem is that the cell will already have a component in it. I would like the cell to be empty, so that the user, from a list, can view which cells are available so that he can create the component he wants there.

  • Yes I understood, but if you use new control() the cell does not stay "as if empty"?

  • Visibly yes, but there is a logic that operates on my Tablelayoutpanel, so that, existing one component there another cannot be created.

  • I see no other way to do this, with tableLayoutPanel1.Controls.Add(), without passing a Control. Instead of new control() use new control("Vazio");. In your logic check the property Text of Control and if it is "Empty" let another be created.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.