2015年6月10日 星期三

[除錯] DataGridView RowValidating事件, 當按Escape取消時, 不要引發該事件...

as title...

參考:
Escaping DataGridView Row creation fires RowValidating. How to avoid this?

1)
private void dataGridView1_KeyDown(object sender, KeyEventArgs e) 
     if (e.KeyCode == Keys.Escape) 
          this.dataGridView1.RowValidating -= 
               new System.Windows.Forms.DataGridViewCellCancelEventHandler(this.dataGridView1_RowValidating); 

     this.dataGridView1.RowValidating += 
          new System.Windows.Forms.DataGridViewCellCancelEventHandler(this.dataGridView1_RowValidating); 
}


2)
if (!view.IsCurrentRowDirty ) return;