[英]How to set borderstyle of a datagridview column at runtime (.Net Framework 4.0)?
我有一个绑定到数据源的只读datagridview。 它有两列。 现在,我希望第一列没有单元格边框样式; 第二个具有“全部”(即,单元的所有侧面均应具有边框)作为单元的边框样式。 在将datagridview绑定到数据源之前,我正在编写如下所述的内容,但是它没有任何效果。 假设有问题的列名为DisplayName。
Dim newStyle As New DataGridViewAdvancedBorderStyle()
With newStyle
.Top = DataGridViewAdvancedCellBorderStyle.Single
.Left = DataGridViewAdvancedCellBorderStyle.Single
.Bottom = DataGridViewAdvancedCellBorderStyle.Single
.Right = DataGridViewAdvancedCellBorderStyle.Single
End With
DisplayName.CellTemplate.AdjustCellBorderStyle(newStyle, newStyle, True, True, True, True)
请更正或提出更好的方法。 问候。
Private Sub dgvLegends_CellPainting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles dgvLegends.CellPainting
'Draw custom cell borders.
'If current column is DisplayName...
If dgvLegends.Columns("DisplayName").Index = e.ColumnIndex AndAlso e.RowIndex >= 0 Then
Dim Brush As New SolidBrush(dgvLegends.ColumnHeadersDefaultCellStyle.BackColor)
e.Graphics.FillRectangle(Brush, e.CellBounds)
Brush.Dispose()
e.Paint(e.CellBounds, DataGridViewPaintParts.All And Not DataGridViewPaintParts.ContentBackground)
ControlPaint.DrawBorder(e.Graphics, e.CellBounds, dgvLegends.GridColor, 1, ButtonBorderStyle.Solid, dgvLegends.GridColor, 1, ButtonBorderStyle.Solid, dgvLegends.GridColor, 1, ButtonBorderStyle.Solid, dgvLegends.GridColor, 1, ButtonBorderStyle.Solid)
e.Handled = True
End If
End Sub
尝试CSS?
.style1
{
border:none;
width: 100%;
}
.style1 td+td
{
border:1px solid red;
}
<table cellpadding="2" class="style1">
<tr>
<td>a
</td>
<td>d
</td>
</tr>
<tr>
<td>b
</td>
<td>c
</td>
</tr>
</table>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.