【发布时间】:2017-07-14 19:37:45
【问题描述】:
您好,我想隐藏或禁用第三列中的按钮,我打算在每次单击时添加行。麻烦的是,以前的按钮是活动的,可以添加行。如何将按钮仅放在最后一行?
这是我的工作代码:
Private Sub dgAppliances_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgAppliances.CellContentClick
If e.ColumnIndex <> 2 Then
Exit Sub
Else
If Me.dgAppliances.RowCount - 1 = 20 Then
MsgBox("Maximum of 20 appliances only.")
Else
Me.dgAppliances.Rows.Add()
End If
End If
End Sub
但是当我添加一些代码时:
Private Sub dgAppliances_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgAppliances.CellContentClick
If e.ColumnIndex <> 2 Then
Exit Sub
Else
If Me.dgAppliances.RowCount - 1 = 20 Then
MsgBox("Maximum of 20 appliances only.")
Else
Me.dgAppliances.Rows.Add()
Dim cell As DataGridViewButtonCell = dgAppliances.Rows(0).Cells(2)
cell.Value = String.Empty
cell = New DataGridViewColumn()
cell.ReadOnly = True
End If
End If
End Sub
这行 cell = New DataGridViewColumn() 有错误。
它说,“System.Windows.Forms.DataGridViewColumn”不能转换为“System.Windows.Forms.DataGridViewButtonCell”。
谁能帮我解决这个问题? TIA。
【问题讨论】:
标签: mysql vb.net datagridview xampp