Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:

VB
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
Posted
Updated 23-Feb-17 19:16pm
v3

 
Share this answer
 
Comments
Jhay0103 24-Feb-17 4:02am    
I already look at it and it has more codes. But thanks for the help sir. :)
Graeme_Grant 24-Feb-17 4:28am    
The example has more but the key code you require is there.
Also, there is this in the Related Questions sidebar on the right of this page: [C#] Disable Button in DataGridView[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900