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:
private
void
radGridView1_RowsChanging(
object
sender, 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:
private
void
radGridView1_CellValueChanged(
object
sender, GridViewCellEventArgs e)
{
IEditableObject editbaleObject = e.Row.DataBoundItem
as
IEditableObject;
DataRowView dataRowView = e.Row.DataBoundItem
as
DataRowView;
if
(editbaleObject !=
null
)
{
editbaleObject.EndEdit();
}
if
(dataRowView !=
null
)
{
var test = dataRowView.DataView.Table;
string
whatiswas = test.ToString();
string
curTable = 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);
}
else
if
(curTable ==
"rep_assigned_stop_matrix"
)
{
//this.rep_assigned_stop_matrixTableAdapter.Update(dataRowView.Row);
this
.rep_assigned_stop_matrixTableAdapter.Update(first_choice_mainDataSet);
}
}