adamtrask
asked on
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_CellContentC lick 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_CellContentC lick
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
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_CellContentC
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_CellContentC
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
Add checks within the event handler to find out which column was clicked to determine the button that was clicked.
ASKER
Not quite sure how to do that CodeCruiser...
Please show me.,
thanks
Please show me.,
thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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_CellContentC lick(objec t sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == IndexOfDelete)
And:
private void dataGridView1_CellContentC lick(objec t sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex ==dataGridView1.Delete)
Same errors... obviously this is not the correct way of doing it....
I tried:
private void dataGridView1_CellContentC
{
if (e.ColumnIndex == IndexOfDelete)
And:
private void dataGridView1_CellContentC
{
if (e.ColumnIndex ==dataGridView1.Delete)
Same errors... obviously this is not the correct way of doing it....
Did you set IndexOfDelete to some value? It needs to be column index of the delete button.
ASKER
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
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
ASKER
I finally got it, sorry for being a bit slow.
thanks
thanks