void ApplyValues() { bool asked = false; bool accept = false; // just before the grid is cleared, check to see if anything changed. foreach (DataGridViewRow row in dataGridViewGames.Rows) { if (row.Cells[1].Value != row.Cells[3].Value) { if (!asked) { accept = (MessageBox.Show("Save changes?", "Values Changed", MessageBoxButtons.YesNo) == DialogResult.Yes); asked = true; } if (!accept) { return; } DataRow[] conf_row = game_config.Select(SessionGame.PrimaryKey + "=" + row.Cells[2].Value.ToString()); if (conf_row.Length > 0) { conf_row[0]["rate"] = row.Cells[1].Value; } else { MessageBox.Show("Lost the related session game group game order row/configuration."); } } } // asked is also 'changed' if (asked) { game_config.CommitChanges(); } }