Reputation: 718
I want to get a blank row. So I want to hide grid lines in a specific row. How can I do this?
There is
Grid.CellBorderStyle = DataGridViewCellBorderStyle.None;
but this can be applied to the grid.
Upvotes: 7
Views: 4230
Reputation: 7082
This is not perfect but I hope you can get some idea.
Design of DataGridView
this.dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.None;
this.dataGridView1.AllowUserToResizeRows = false;
this.dataGridView1.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;
private void dataGridView1_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
{
if (e.RowIndex == -1) return;
// Calculate the bounds of the row.
Rectangle rowBounds = new Rectangle(
this.dataGridView1.RowHeadersWidth, e.RowBounds.Top,
this.dataGridView1.Columns.GetColumnsWidth(
DataGridViewElementStates.Visible) -
this.dataGridView1.HorizontalScrollingOffset + 1,
e.RowBounds.Height);
// Paint the custom background.
using (Brush backbrush =
new SolidBrush(this.dataGridView1.GridColor), backColorBrush = new SolidBrush(Color.White))
{
using (Pen gridLinePen = new Pen(backbrush))
{
//Apply to spicific row
if (e.RowIndex == 2)
{
e.Graphics.FillRectangle(backbrush, rowBounds);
// Draw the inset highlight box.
e.Graphics.DrawRectangle(Pens.Blue, rowBounds);
}
}
}
}
private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
if (e.RowIndex == -1) return;
if (e.Value != null)
{
// Draw the text content of the cell, ignoring alignment of e.RowIndex != 2
if (e.RowIndex != 2)
{
e.Graphics.DrawString((String)e.Value, e.CellStyle.Font,
Brushes.Black, e.CellBounds.X + 2,
e.CellBounds.Y + 2, StringFormat.GenericDefault);
}
}
e.Handled = true;
}
References:
DataGridView.RowPrePaint Event
DataGridView.CellPainting Event
Upvotes: 0
Reputation: 11782
Untested, but you should be able to get what you need by handling the CellPainting event and excluding the DataGridViewParts.Border
e.Paint(e.ClipBounds, DataGridViewPaintParts.All ^ DataGridViewPaintParts.Border);
e.Handled = true;
Upvotes: 1