It looks like this block of code is causing the issue
if (codeSetView == null)
{
codeSetView.AddNewItem(new CodeSet());
}
If codeSetView
is null
you cant use codeSetView.AddNewItem
.
You will have to initiate codeSetView
before adding items.
eg:
if (codeSetView == null)
{
codeSetView = new ...... or (ListCollectionView)CollectionViewSource.GetDefaultView(codeSetData);
codeSetView.AddNewItem(new CodeSet());
}