I have a databound grid.
When I right click on a row and choose "delete row" I want it to delete it in the database as well.
My code seems pretty simple:
privatevoidradGridView1_RowsChanging(objectsender, GridViewCollectionChangingEventArgs e) { if(e.Action == Telerik.WinControls.Data.NotifyCollectionChangedAction.Remove) { DialogResult dr = MessageBox.Show("Are you sure?", "Delete Row", MessageBoxButtons.YesNo); if(dr == DialogResult.Yes) { e.Cancel = false; this.radGridView1.EndUpdate(); this.rep_assigned_stop_matrixTableAdapter.Update(first_choice_mainDataSet); } else { e.Cancel = true; } } }
It steps through it fine, the row is gone but the database does not get updated UNLESS I edit another field, then it calls this and it not only does the field edit but it also removes the row:
privatevoidradGridView1_CellValueChanged(objectsender, GridViewCellEventArgs e) { IEditableObject editbaleObject = e.Row.DataBoundItem asIEditableObject; DataRowView dataRowView = e.Row.DataBoundItem asDataRowView; if(editbaleObject != null) { editbaleObject.EndEdit(); } if(dataRowView != null) { var test = dataRowView.DataView.Table; stringwhatiswas = test.ToString(); stringcurTable = dataRowView.DataView.Table.ToString(); if(dataRowView != null&& this.allowEdits.Checked) { if(curTable == "rep_info") { //this.rep_infoTableAdapter.Update(first_choice_mainDataSet.rep_info); this.rep_infoTableAdapter.Update(dataRowView.Row); } elseif(curTable == "rep_assigned_stop_matrix") { //this.rep_assigned_stop_matrixTableAdapter.Update(dataRowView.Row); this.rep_assigned_stop_matrixTableAdapter.Update(first_choice_mainDataSet); } }