Click here to Skip to main content
15,441,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Does anyone know how to span multiple rows in a TableLayoutPanel without adding new rows or columns? I have 3 columns with 6 rows in each. I need to span a row, but when I do, it adds new rows. I need to span the rows WITHOUT adding new ones. Each row contains a textbox control. Is this possible?

Thank you! My code is below:

private void control_TextChanged(object sender, EventArgs e)
            string str = control.Text;
            if (str.Contains("Follow-Up"))
                table.SetColumnSpan(control, 1);
                table.SetRowSpan(control, 2);
                control.BackColor = Color.PowderBlue;
            else if (str.Contains("Admit"))
                table.SetColumnSpan(control, 1);
                table.SetRowSpan(control, 4);
                control.BackColor = Color.Lavender;
                table.SetColumnSpan(control, 1);
                table.SetRowSpan(control, 1);
                control.BackColor = Color.White;

        private void textbox_Enter(object sender, EventArgs e)
            control = (TextBox)sender;

What I have tried:

I have set the GrowStyle to None, but that simply gives an error when trying to span a row.
Gerry Schmitz 7-Jun-19 17:23pm    
Maybe you should explain "why" or "what" you want? Some bizarre text changed behavior? Not. Maybe try text wrapping or a "bigger box".
dragnscalearmor 7-Jun-19 18:28pm     CRLF
I apologize for the confusion. The text boxes don't matter. What I would like is the ability to span a cell into the cell below it. When I do this, a new cell is added. I don't want a new cell added, I want to only span existing cells. I have three columns with six rows in each. I will need to span some of the rows together occasionally at runtime, and I can do this just fine. The problem is when spanning a row to another row, yet another row is created by default, which shifts the rest of the cells over, misaligning everything below them. In my program, there can only be 18 cells total.
Gerry Schmitz 8-Jun-19 2:22am    
What do you mean the text box "doesn't matter"? That's the "control" you're spanning. And you need "something" that is spanned. Or you need to come up with a better explanation.
dragnscalearmor 9-Jun-19 0:14am    
You are correct. The text boxes are being spanned. The problem occurs because when the text box spans, everything in the cells below it and to the right of it get shifted over. But I need them to not shift when a span occurs above them.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900