Click here to Skip to main content
15,909,822 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
I've added a DataGridViewButtonColumn :

C#
DataGridViewButtonColumn btnCancel = new DataGridViewButtonColumn();
btnCancel.Name = "btnCanel";
btnCancel.HeaderText = "Cancel";
btnCancel.Text = "CANCEL";
btnCancel.FlatStyle = FlatStyle.Popup;
btnCancel.DefaultCellStyle.ForeColor = Color.Red;
btnCancel.DefaultCellStyle.BackColor = Color.Gainsboro;
btnCancel.UseColumnTextForButtonValue = true;

dataGridView1.Columns.Insert(0, btnCancel);

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
      if (e.ColumnIndex == 0 && e.RowIndex >= 0)
      {
          ulong ordID = (ulong)dataGridView1.Rows[e.RowIndex].Cells[1].Value;
          myFunc(ordID);
      }
}


dataGridView1 is bound to a bindingList. this bingList is updated throughout the day. The objects are being added, removed and updated to the bindingList. When I click I trying to send the the cell results to my method but the cellClick event is not firing.

Can someone please tell me what I'm doing wrong here?

Thanks in advance,
-DA
Posted
Updated 6-Mar-12 14:36pm
v3
Comments
Dinesh Mani 6-Mar-12 23:19pm    
Apologies if I sound naive, but I've not worked on ASP.Net for some time so not sure if there have been changes to the way newer versions wire-up events.

Anyway, my question is where is the wire-up for the cancel button to this event handler? As per your code you are creating the button at runtime, so you need to assign the event handler at runtime. Try assigning an event handler for this button.
d.allen101 7-Mar-12 3:33am    
this is a WinForm and there is no "wire-up". buttons don't have clickEvents within dataGridView at not to my knowledge.
BobJanova 7-Mar-12 7:06am    
Have you actually attached this event handler to the grid? Not trying to be funny but that's usually why events don't fire.
d.allen101 7-Mar-12 9:52am    
sorry everyone! I didn't realize that I had deleted my previous dataGridView and replaced it with another and the "eventHandler" was still present in my code but it wasn't "linked" to the new dataGridView...

sorry for wasting everyone's time.

1 solution

Have you tried using the CellContentClick event in place of CellClick?

The documentation is confusing as .NET 2.0 [^] says that's the one to use but .NET 4.0 [^] says use either.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900