Reputation: 17
I have this code here,
When I click on the Modify button, I got a message box. After I click on the x
button to close it, the message box appears again. I really don't know why this happens.
private void dataGridUsers_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (dataGridUsers.Columns[e.ColumnIndex] is DataGridViewButtonColumn &&
e.RowIndex >= -1 && dataGridUsers.Columns[e.ColumnIndex].Name == "Modify")
{
MessageBox.Show("");
}
}
Upvotes: 1
Views: 574
Reputation: 3571
My Guess: You are re-assigning the event handler again and again somewhere in your code. That is the problem you are getting the message box triggered twice.
dataGridUsers.CellContentClick += new DataGridViewCellEventHandler(dataGridUsers_CellContentClick);
To fix the issue, you need to assign the above event handler only in the function where you need.
Upvotes: 2