I am using Entity Framework code first in my application. I have a AddNewRow and having trouble to first find the right event that would capture addnewrow. I have used CollectionChanged event
(sfDataGridProposals.View as CollectionViewAdv).CollectionChanged += sfDataGridProposals_CollectionChanged;
private void sfDataGridProposals_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
{
Proposal newRecord = e.NewItems as Proposal;
Proposal proposal = new Proposal();
proposal.ProposalActive = newRecord.ProposalActive;
proposal.ProposalAwardDate = newRecord.ProposalAwardDate;
proposal.ProposalCompanyID = newRecord.ProposalCompanyID;
proposal.ProposalDueDate = newRecord.ProposalDueDate;
proposal.ProposalDueTime = newRecord.ProposalDueTime;
proposal.ProposalEngineerID = newRecord.ProposalEngineerID;
proposal.ProposalGroupID = newRecord.ProposalGroupID;
proposal.ProposalName = newRecord.ProposalName;
proposal.ProposalNo = newRecord.ProposalNo;
proposal.ProposalNotes = newRecord.ProposalNotes;
proposal.ProposalOwnerID = newRecord.ProposalOwnerID;
proposal.ProposalStatusID = newRecord.ProposalStatusID;
proposal.ProposalSubmitted = newRecord.ProposalSubmitted;
proposal.ProposalSubmittedDate = newRecord.ProposalSubmittedDate;
_MainFormContext.Proposals.Add(proposal);
_MainFormContext.SaveChanges();
}
}
However it gives me an error newRecord was null.
Is there any other way to addnewrow?