Q:

Button Column in a datagrid

I have a grid and the first column is a button for each line,with Excluir ("Delete").

When i click in the button i need to recover the button action and which row it was clicked,i'm trying this but don't work.
Private Sub dgAdm_CellClick(ByVal sender As System.Object, ByVal e As DataGridViewCellEventArgs)

     IF e.ColumnIndex = dgAdm.Columns["Delete"].Index AndAlso e.RowIndex >= 0

            Console.WriteLine("Button on row {0} clicked", e.RowIndex)
     End

Someone knows what i'm missing

A:

You need to refer to the sender parameter, because it is an Object type you must cast it to DataGridview first. here is an example in vb.net how to extract the row and column number via CellClick event:
Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
    Dim rowNum As Integer = CType(sender, DataGridView).CurrentCell.RowIndex ' get row number
    Dim colNum As Integer = CType(sender, DataGridView).CurrentCell.ColumnIndex ' get col number

    If colNum = 1 Then ' the index of the "delete" button column
        MsgBox("the row number that was clicked: " & rowNum)
    End If

End Sub

