I want to delete a row from gridview and database – I write some code but this code just delete the first row of my gridview!
Please help me. I used Entity Framework and wpf C#.
using (AccountingEntities cntx = new AccountingEntities())
{
Producer item = this.grdProducers.SelectedItem as Producer;
cntx.DeleteObject(cntx.Producers.First(x => x.ID == item.ID));
cntx.SaveChanges();
dataPager.Source = cntx.Producers.ToList();
}
I find the solution: when i open the dialog for confirming the delete action, selected item changed. i should select the entityId before opening the dialog. the below code show how to do this: