I am trying to cross out a whole line in a Datagridview. This is what I am currently doing:
DataGridViewCellStyle style = new DataGridViewCellStyle(); style.Font = new Font(dgview.Font.OriginalFontName, 7, FontStyle.Strikeout); dgview.Rows[dgview.RowCount - 1].DefaultCellStyle.ApplyStyle(style);
This approach only removes part of the cells that have any text in them. I would like to have a continuous out, that is, one line that goes through the line.
I would appreciate any help with this. Thanks in advance.
EDIT: That was like the likely answer in another question: "Probably the easiest way to do this if all the lines are the same height is to apply a background image to it that just has a large line through the center, the same color as the test" .
If all else fails, I will go with that. But is there nothing simpler?
EDIT2: Mark proposal has been implemented with a small number of settings. The cellbound property does not work properly for me, so I decided to get the location using rowindex and rowheight.
private void dgv_CellPainting(object sender,DataGridViewCellPaintingEventArgs e) { if (e.RowIndex != -1) { if (dgv.Rows[e.RowIndex].Cells["Strikeout"].Value.ToString() == "Y") { e.Paint(e.CellBounds, e.PaintParts); e.Graphics.DrawLine(new Pen(Color.Red, 2), new Point(e.CellBounds.Left, gridHeaderHeight+ e.RowIndex * rowHeight+ rowHeight/2), new Point(e.CellBounds.Right, gridHeaderHeight+ e.RowIndex * rowHeight+ rowHeight/2)); e.Handled = true; } } }
source share