Well, I play with the trick, I hope this helps all of you, I track the changes using the bindingsource CurrentItemChanged method. Here I used the tag property for datagridview to mark the changes, you can use the variable:
private void cONTRACTERBindingSource_CurrentItemChanged(object sender, EventArgs e) { if (cONTRACTERDataGridView.Tag==null) { DataRow ThisDataRow = ((DataRowView)((BindingSource)sender).Current).Row; if (ThisDataRow.RowState == DataRowState.Modified) cONTRACTERDataGridView.Tag = "1"; } }
Remember that this trigger could be fired many times, so both if statements control the launch once, really. Finally, you can use this code in the exit button handler, as in my code code here:
private void btExit_Click(object sender, EventArgs e) { if (cONTRACTERDataGridView.Tag.Equals("1")) { if (MessageBox.Show("Do you want to save the changes..!?", "Save Changes", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) cONTRACTERBindingNavigatorSaveItem_Click(null, null); } this.Close(); }
Discard changes, reset flag. Hope this works for you, too.
Hi
source share