更改datagridview cellstyle边框颜色

时间:2016-11-08 13:31:31

标签: .net vb.net winforms datagridview

我正在尝试根据单元格的背景颜色更改单元格边框颜色

这就是我用过的东西

PyGILState_Release

这是结果

enter image description here

我不知道目前看到的白线

1 个答案:

答案 0 :(得分:1)

作为一个选项,您可以设置边框样式yo none:

Me.DataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.None

然后处理CellPainting事件并绘制边框:

Private Sub DataGridView1_CellPainting(sender As Object, _
    e As DataGridViewCellPaintingEventArgs) Handles DataGridView1.CellPainting

    If (e.ColumnIndex < 0 OrElse e.RowIndex < 0) Then Return
    e.Paint(e.CellBounds, DataGridViewPaintParts.All)
    Dim r = e.CellBounds
    e.Graphics.DrawLine(Pens.Black, r.Left, r.Top, r.Right, r.Top)
    e.Graphics.DrawLine(Pens.Black, r.Left, r.Bottom, r.Right, r.Bottom)
    e.Handled = True
End Sub

enter image description here