如何在datagridview中禁用或隐藏按钮 [英] How to disable or hide button in datagridview
本文介绍了如何在datagridview中禁用或隐藏按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好我想隐藏或禁用我的第3列中的按钮,我打算每次单击时添加行。混乱是,以前的按钮是活动的,可以添加行。我怎样才能将按钮放在最后一排?
有谁可以帮我这个? TIA。
我的尝试:
私有 Sub dgAppliances_CellContentClick(发件人 As 对象,e As DataGridViewCellEventArgs)句柄 dgAppliances.CellContentClick
如果 e.ColumnIndex<> 2 然后
退出 < span class =code-keyword> Sub
Else
如果 我 .dgAppliances.RowCount = 20 然后
MsgBox( 最多只有20个设备。)
< span class =code-keyword> Else
dgvAppsRowNo + = 1
我 .dgAppliances.Rows.Add()
我 .dgAppliances.Rows(dgvAppsRowNo).Cells( 0 )。值= dgvAppsRowNo + 1
Dim cell As DataGridViewButtonCell = dgAppliances.Rows(dgvAppsRowNo).Cells( 2 )
cell.Value = New DataGridTextBoxColumn()
cell。 ReadOnly = True
结束 如果
结束 如果
结束 Sub
解决方案
Microsoft有一个如何执行此操作的示例:如何:在Windows窗体DataGridView控件中禁用按钮列中的按钮 [ ^ ]
此外,还有这在相关问题此页右侧的侧栏: [C#]禁用按钮在DataGridView中 [ ^
Hi I want to Hide or Disable the button in my 3rd column which I intend to add row every time I click it. The mess is, the previous buttons are active and can add row. How can I place the button only in the last row?
Can anyone help me about this? TIA.
What I have tried:
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 = 20 Then
MsgBox("Maximum of 20 appliances only.")
Else
dgvAppsRowNo += 1
Me.dgAppliances.Rows.Add()
Me.dgAppliances.Rows(dgvAppsRowNo).Cells(0).Value = dgvAppsRowNo + 1
Dim cell As DataGridViewButtonCell = dgAppliances.Rows(dgvAppsRowNo).Cells(2)
cell.Value = New DataGridTextBoxColumn()
cell.ReadOnly = True
End If
End If
End Sub
解决方案
Microsoft has an example of how to do this: How to: Disable Buttons in a Button Column in the Windows Forms DataGridView Control[^]
Also, there is this in the Related Questions sidebar on the right of this page: [C#] Disable Button in DataGridView[^]
这篇关于如何在datagridview中禁用或隐藏按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文