Click event for button in DataGridViewButtonColumn


I've got  a DataGridView on a windows form with various columns added by the Data Source. I also added a DataGridViewButtonColumn. The problem I'm having is that I have no idea how to add code to these buttons. Pls Help


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

To handle the “button click,” you need to handle the CellClick event on the grid, determine if it was a button cell that was clicked, and then take the appropriate action for your application. This involves taking the event argument from the CellClick event, checking its ColumnIndex property against the column index of button columns in your grid, and then calling the button click handling code from there based on the row index, or the contents of that cell or others in that row.

cErasmusAuthor Commented:
Can you perhaps help me with a bit of sample code?
Private Sub DataGridView1_CellClick( _
  ByVal sender As System.Object, _
  ByVal e As System.Windows.Forms. _
  DataGridViewCellEventArgs) _
  Handles DataGridView1.CellClick

    If DataGridView1.Columns(e.ColumnIndex).Name = _
      "Details" Then
        MessageBox.Show("You picked " & _
          DataGridView1.Rows(e.RowIndex). _
    End If
End Sub

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cErasmusAuthor Commented:
Thank you very much!
Thank you!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.