Click here to Skip to main content
15,889,116 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Thanks in advance....Say for example I have 5 Rows in a tablelayout panel.

But how do I add the line after every 2 rows?


So, the first thing we observe is there should not be any seperator/vertical gridlines between columns.
Then how do we add the line after 2 rows?
Also, usually we add lines/labels for each cell in a column. But in my case I need a full line and not for a cell.

What I have tried:

By using label control. Clear Text of label, set AutoSize to false , Borderstyle to FIxedSingle. and Height to 1.
Posted
Updated 4-Feb-21 10:27am
Comments
[no name] 4-Feb-21 14:53pm    
FWIW, this is trivial with WPF / UWP: A "Grid"; and a Rectangle with Height = 1+ spanning one or more columns.

You can use custom Painting method. See: c# - Draw only outer border for TableLayoutPanel Cells - Stack Overflow[^]. For example:

C#
private void tableLayoutPanel_CellPaint(object sender, TableLayoutCellPaintEventArgs e)
{
        if(e.Row > 1 && e.Row % 2 == 0 ) 
            e.Graphics.DrawLine(Pens.Black, e.CellBounds.Location, new Point(e.CellBounds.Right, e.CellBounds.Top));
}


Or... you can create custom control, which will display data in 2 rows and horizontal line below.
 
Share this answer
 
Comments
Member 15028582 4-Feb-21 21:11pm    
tq ji
Maciej Los 5-Feb-21 0:25am    
What?
RickZeeland 5-Feb-21 4:07am    
He's one of the knights who say "ji"
5d :)
Maciej Los 5-Feb-21 4:23am    
And what it means?
 
Share this answer
 

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