沒有實際的方法來隱藏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