没有实际的方法来隐藏DataGridViewButtonCell
。目前我只能看到两个选项:
- 使用填充按钮移动按钮,如图所示here。我将提供类似的VB.NET代码
- 将
Cell
到DataGridViewTextBoxCell
和ReadOnly
属性设置为真
使用Padding
:
Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
If DataGridView1.Rows(e.RowIndex).Cells(6).GetType() Is GetType(DataGridViewButtonCell) Then
Dim columnWidth As Integer = DataGridView1.Columns(e.ColumnIndex).Width
Dim newDataGridViewCellStyle As New DataGridViewCellStyle With {.Padding = New Padding(columnWidth + 1, 0, 0, 0)}
DataGridView1.Rows(e.RowIndex).Cells(6).Style = newDataGridViewCellStyle
End If
End Sub
使用DataGridViewTextBoxCell
:
Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
If DataGridView1.Rows(e.RowIndex).Cells(6).GetType() Is GetType(DataGridViewButtonCell) Then
Dim newDataGridViewCell As New DataGridViewTextBoxCell
DataGridView1.Rows(e.RowIndex).Cells(6) = newDataGridViewCell
newDataGridViewCell.ReadOnly = True
End If
End Sub
这两个应该给你的效果不显示按钮。
的[有时候我想隐藏在DataGridViewButtonColumn按钮](可能的复制http://stackoverflow.com/questions/25200679/sometimes-i-want-to-hide-buttons-in-a -datagridviewbuttoncolumn) – JohnG
您可以将启用设置为false,或者干脆忽略您想要禁用的按钮的点击事件。 – JohnG
都是.NET的'DataGridViewButtonColumn' – JohnG