Hi everyone I use Visual Studio 2012 with c# and wpf.
I have a datagrid and in it I enabled editing and adding new rows. Now I have to distinguish between the two so I can direct them to the separate methods for updating or inserting into the database. I tried using the observable collection's collection changed method:
void Opcine_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add) { Opcina opc = new Opcina(); opc.IsNew = true; } }
And it hits. The problem is that I set the IsNew to true but when it comes time to save stuff by clicking on a button the IsNew is set to false for all the rows including the new one. What am I doing wrong?
My save method:
public void SpasiOpcinu() { foreach (Opcina opc in _opcine) { _opcina = opc; if (opc.IsNew==true) { _glavniRepository.SpasiOpcinu(_opcina); opc.IsNew = false; } else { _glavniRepository.IzmijeniOpcinu(_opcina); } } }
Thanks for the help