I tend to separate my data loading into its own method. As such, I can then detach handlers which may be fired during a load or refresh, and then simply re-attach when that process is finished. This also makes it easier (where applicable) to refresh the dgv data from other places in the code.
The key, in the context of your problem, is:
- detach handler
- fill
DataGridView
or attach data source, however you are doing that.
- re-attach handler
private void LoadDataGrid()
{
this.dataGridView1.CellValueChanged -= new
DataGridViewCellEventHandler(dataGridView1_CellValueChanged);
// Your code to load data here
this.dataGridView1.CellValueChanged +=new
DataGridViewCellEventHandler(dataGridView1_CellValueChanged);
}
void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
// Your code to handle the cell value changing
}