Trigger action on DataGridViewButtonColumn

retkehing

Well-known member
Joined
Feb 5, 2006
Messages
153
Programming Experience
Beginner
The user can trigger action by clicking on the DataGridViewButtonColumn of DataGridView. I have successfully done as the following code.

VB.NET:
Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
 
        Try
 
                Remove_Emp_No = DataGridView1.Rows(e.RowIndex).Cells("Delete").Value
                TextBox1.Text = Remove_Emp_No
 
            OleDbCommand1.CommandText = "DELETE FROM Emp_Profile WHERE emp_no='" & Remove_Emp_No & "'"
            OleDbCommand1.Connection = OleDbConnection1
 
                OleDbConnection1.Open()
                Dim DReader1 As OleDb.OleDbDataReader = OleDbCommand1.ExecuteReader
                OleDbConnection1.Close()
 
            End If
        Catch err As System.Exception
            MessageBox.Show(err.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
 
    End Sub

When the DataGridView consists of more than one DataGridViewButtonColumn, i can't specify different actions for each DataGridViewButtonColumn. May i know to solve it? Thank you.
 
Last edited:
DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick


Ask the e object which cell was clicked, and do your different action..
 
Back
Top