adding more than one column button to a dataGridView

Hi,

I am using an unbound dataGridView to display data from an sql database table.  
I tried experimenting by adding a column button to the dataGridView. I did this using the Add column option in the dataGridView Tasks.

With this I created the first column button, and by double clicking that button arrived at the
dataGridView1_CellContentClick which I used to  add code that deletes the selected row.

When I tried to create a second column button I found that by double clicking on it I arrive at the above event, i.e the same dataGridView1_CellContentClick

Obviously I could not use the same event to execute different tasks (like updating and deleting).

My question is this: Are we only allowed to create a single column button for a dataGridView or am I doing some thing wrong....?

Thanks
adamtraskAsked:
Who is Participating?
 
CodeCruiserCommented:
Try

If e.ColumnIndex = IndexOfButton1 Then
   'do button 1 stuff
ElseIf e.ColumnIndex = IndexOfButton2 Then
  'do button 2 stuff
...
End If
0
 
CodeCruiserCommented:
Add checks within the event handler to find out which column was clicked to determine the button that was clicked.
0
 
adamtraskAuthor Commented:
Not quite sure how to do that CodeCruiser...
Please show me.,

thanks
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
adamtraskAuthor Commented:
Still can't figure it out.... The two buttons I have are named Delete and Update and their HeaderText are given the same names....

I tried:
  private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == IndexOfDelete)
And:

 private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex ==dataGridView1.Delete)

Same errors... obviously this is not the correct way of doing it....
0
 
CodeCruiserCommented:
Did you set IndexOfDelete to some value? It needs to be column index of the delete button.
0
 
adamtraskAuthor Commented:
CodeCruiser:

Sorry for not responding. I was trying too many things and ended up messing up the form or many of the controls on the form... I have too many errors to fix.

As for assigning a value to the index of the Delete column Button the answer is no. Simply because I created that button using the Add column option on the dataGridView Tasks, and I didn't see an indexOf property any where
0
 
adamtraskAuthor Commented:
I finally got it, sorry for being a bit slow.

thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.