数据网格中的按钮列

时间:2017-01-13 16:38:56

标签: vb.net datagridview

我有一个网格,第一列是每行的一个按钮,带有Excluir("删除")。

enter image description here

当我点击按钮时,我需要恢复按钮操作以及点击它的哪一行,我尝试了这个但是没有工作。

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

有人知道我错过了什么

1 个答案:

答案 0 :(得分:1)

您需要参考发件人参数,因为它是Object类型,您必须先将其强制转换为DataGridview。这是vb.net中如何通过CellClick事件提取行号和列号的示例:

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