Hello,
Thanks for your post.
I performed a test on my side. I tried the following code, but I cannot reproduce the issue on my machine.
DataTable dt = new DataTable();
private void CellClickTest_Load(object sender, EventArgs e)
{
dt.Columns.Add("name");
dt.Columns.Add("price", typeof(decimal));
dt.Columns.Add("volume", typeof(int));
dt.Rows.Add("item1", 1.25, 3);
dt.Rows.Add("item2", 2.25, 8);
dt.Rows.Add("item3", 4.25, 6);
dt.AcceptChanges();
this.dataGridView1.DataSource = dt;
DataGridViewButtonColumn bc = new DataGridViewButtonColumn();
bc.HeaderText = " ";
bc.Text = "Add";
this.dataGridView1.Columns.Add(bc);
this.dataGridView1.CellClick += new DataGridViewCellEventHandler(dataGridView1_CellClick);
}
int count = 0;
void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0 && e.ColumnIndex == 3)
{
count++;
this.lblcount.Text = count.ToString();
}
}
There must be something wrong in the other code rather than the CellClick event handler, please make sure that you didn't register the event twice. Could you please send me a simple sample that can reproduce this issue to my mail box[v-rzhang[at]microsoft.com]? I will perform test on my side and keep you updated.
Thanks,
Rong-Chun Zhang
MSDN Subscriber Support in Forum
If you have any feedback on our support, please contact msdnmg[at]microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.