我正在尝试删除 Datagridview 中的整行。这就是我目前正在做的事情:
DataGridViewCellStyle style = new DataGridViewCellStyle();
style.Font = new Font(dgview.Font.OriginalFontName, 7, FontStyle.Strikeout);
dgview.Rows[dgview.RowCount - 1].DefaultCellStyle.ApplyStyle(style);
这种方法只会删除单元格中包含任何文本的部分。我想要的是连续的三振,即一条穿过该行的线。
我将不胜感激任何帮助。提前致谢。
编辑:在另一个问题中将此视为可能的答案-“如果所有行都具有相同的高度,那么可能最简单的方法就是应用一个背景图像,该背景图像只有一条穿过中心的大线,颜色相同作为测试。”
如果其他一切都失败了,那么我会选择这个。但难道就没有更简单的事情了吗?
EDIT2:通过一些调整实现了马克的建议。 cellbound 属性对我来说无法正常工作,因此我决定使用 rowindex 和 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;
}
}
}