How to run Run CellEndEdit only when Cell ValueChanged in DataGridView

后端 未结 5 1314
囚心锁ツ
囚心锁ツ 2021-01-13 04:45

i want to run CellEndEdit only when value of cell is changed, tried putting

if (dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() == e.For         


        
5条回答
  •  长发绾君心
    2021-01-13 05:12

    Instead of performing your tasks in CellEndEdit, put them in CellValueChanged. It is fired only when cell value is changed. Please note that it will fire when your DataGridViews are initially populated, but to handle that, you can put just one variable saying formInitialized or something, to make sure that you are not executing your CellEndEdit when you populate your data grids.

    And to answer your question, there is no way to figure out if value is changed when CellEndEdit is fired, because it is always fired when cell gets out of edit mode. The only solution is, like you proposed, to store the old value externally, but you already noticed why is that bad (though it works really good in most of the cases).

提交回复
热议问题