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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

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
CodeCruiserCommented:
Try

If e.ColumnIndex = IndexOfButton1 Then
   'do button 1 stuff
ElseIf e.ColumnIndex = IndexOfButton2 Then
  'do button 2 stuff
...
End If
0

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
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

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
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
C#

From novice to tech pro — start learning today.