i have a window that shows a list of entities and i want to edit the selecteitem of gridview in a new window (Not in grid). when i submit my form no error occurred but entity have no changes in database! please help me.
in top of my list window code behind:
private ObservableCollection<Employee> AllEmployeesData { get; set; }
private ListCollectionView View;
and in window_loaded i use this method for fetch data:
public void LoadAllEmployees()
{
IEnumerable<Employee> data = null;
using (ArchiveEntities db = new ArchiveEntities())
{
data = db.Employees.Include("Department");
this.AllEmployeesData = new ObservableCollection<Employee>(data);
}
CollectionViewSource employeeSource = (CollectionViewSource)this.FindResource("AllEmployeesDataSource");
employeeSource.Source = this.AllEmployeesData;
this.View = (ListCollectionView)employeeSource.View;
}
Editbutton click event:
EditEmployeeView win = new EditEmployeeView();
View.EditItem(SelectedEmployee);
win.DataContext = SelectedEmployee;
if ((bool)win.ShowDialog())
{
using (ArchiveEntities db = new ArchiveEntities())
{
Employee employee = db.Employees.Single(x => x.Id == SelectedEmployee.Id);
db.Employees.ApplyCurrentValues(employee);
db.SaveChanges();
View.CommitEdit();
}
}
else
{
View.CancelEdit();
}
all of the above code is in my first window (window that shows a list of entities). and in my second window (window for edit selected item of a first window):
submitbutton click event:
DialogResult = true;
Close();
my problem is: when i submit edit form no error occurred but data dont save in database and when i cancel edit form i get this error:
InvalidOperationException was unhandled: CancelEdit is not supported for the current edit item.