Skip to main content Skip to footer

How to Draw Thick Line Across Some Rows in FlexGrid

When using the FlexGrid as a scheduler with rows representing 15-minute quarters, it can be difficult for users to visually distinguish between different hours. You need a way to draw a bold, straight horizontal line across all columns exactly at the start of every even hour to improve the grid's readability.

Solution
To create a clean and consistent horizontal divider, you should define a custom CellStyle with a thicker border and apply it to the specific rows representing the hour marks. Since modifying row styles can sometimes interfere with vertical grid lines, you then use the OwnerDrawCell event to manually manage the rendering logic, ensuring the vertical borders remain intact and the horizontal line spans the entire width of the grid.

private void C1FlexGrid1_OwnerDrawCell(object sender, C1.Win.C1FlexGrid.OwnerDrawCellEventArgs e)
{
    if(e.Row%3==0)
    {
        c1FlexGrid1.Rows[e.Row].Style = cs;
        Color borderColor = c1FlexGrid1.Styles.Normal.Border.Color;
        int right = e.Bounds.Right - e.Style.Border.Width;
        if (e.Row < c1FlexGrid1.Rows.Fixed || e.Col < c1FlexGrid1.Cols.Fixed)
        {
            return;
        }

        if (c1FlexGrid1.IsCellHighlighted(e.Row, e.Col))
        {
            borderColor = Color.White;
        }
        e.DrawCell();
        e.Graphics.DrawLine(new Pen(borderColor, e.Style.Border.Width), new Point(right, e.Bounds.Top), new Point(e.Bounds.Right - e.Style.Border.Width, e.Bounds.Bottom-3));
        e.Handled = true;
    }
}