private void RegistrationTableColumnChanged(DataColumnChangeEventArgs e) { // If the row is in the process of being added (detached), don't update the cells // only do this if an existing cell is changed if (e.Row.RowState != DataRowState.Detached) { // if this is an identity colum, it is only modified by the db in InsertTableRow() // so don't send an update back if (e.Column.AutoIncrement == false) { // just update the entire row even though just one column was changed // this could be optimized try { registrationDB.UpdateTableRow(e.Row); } catch (Exception ex) { MessageBox.Show(ex.Message); } // Update the view (bottom control) registrationDB.LoadDataTable(dataGridViewDepartmentMajorsCount.DataSource as DataTable); } } }
/// <summary> /// update database with the changed column /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Table_ColumnChanged(object sender, DataColumnChangeEventArgs e) { //Only do this if an existing cell is changed (for update) if (e.Row.RowState != DataRowState.Detached) { //if this is an identity column, it is only modified by the insert tablerow if (e.Column.AutoIncrement == false) { //update the entire row try { registrationDB.UpdateTableRow(e.Row); } catch (Exception ex) { MessageBox.Show(ex.Message); } //reload student datatable registrationDB.LoadDataTable(dataGridViewStudents.DataSource as DataTable); //update view registrationDB.LoadDataTable(dataGridViewDepartmentMajorsCount.DataSource as DataTable); } } }