c# - How stop CellValueChanged firing while populating? -
i have form contains several datagridview's. being cleared , populated programmatically while program running. based on cells being altered in 1 of datagridviews user in form. user changing cell triggers clearing , repopulating datagridviews including 1 interact with.
so question. can avoid cellvaluechanged being triggered everytime datagridviews cleared , repopulated programmatically? instead should triggered when user edits cell in form.
i've tried searching answer no success, hope not duplicate question.
i doubt can stop cellvaluechanged event being triggered, other removing handlers(events still triggered, there won't handlers it):
private dgv_thatcauseschanges_cellvaluechanged(object sender, eventargs e) { this.otherdgv.cellvaluechanged -= this.dgv_otherdgvcellvaluechanged; try // make sure handlers reinstatiated on exception @steve { // change other dgvs } { this.otherdgv.cellvaluechanged += this.dgv_otherdgvcellvaluechanged; } }
or alternative solution add flag, checked in every handler:
private bool ischanging; private dgv_thatcauseschanges_cellvaluechanged(object sender, eventargs e) { this.ischanging = true; try // make sure handlers reinstatiated on exception @steve { // change other dgvs } { this.ischanging = false; } } private dgv_otherdgvcellvaluechanged(object sender, eventargs e) { if (this.ischanging) return; // handle changes }
Comments
Post a Comment