hello... i'm having a rather odd issue and i'm having trouble pin pointing where and why it's happening.... could really use some assistance with this. so i'm new to c#, been doing things in vb mostly, but i wanted to expand my languages since i work off example a lot of the time and most of the examples that i have found are in c#....so.
anyways this is my window: AddRec
public partial class AddRec : Window
{
private BxEntities db = new BxEntities();
private RecCollection RecData;
private CollectionViewSource RecViewSource;
private CollectionViewSource InViewSource;
private CollectionViewSource DirViewSource;
private CollectionViewSource CorViewSource;
private CollectionViewSource HoldsViewSource;
private CollectionViewSource LifeViewSource;
private CollectionViewSource SpecsViewSource;
private CollectionViewSource ToDsViewSource;
private ListCollectionView RecView;
private BindingListCollectionView InView;
private BindingListCollectionView DirView;
private BindingListCollectionView CorView;
private BindingListCollectionView HoldsView;
private BindingListCollectionView LifeView;
private BindingListCollectionView SpecsView;
private BindingListCollectionView ToDsView;
public AddRec()
{
InitializeComponent();
}
public void Window_Loaded(object sender, RoutedEventArgs e)
{
var recs = from r in db.RecTbls
select r;
this.RecData = new RecCollection(recs, db);
this.RecSource = (CollectionViewSource)this.TryFindResource("RecViewSource");
this.InViewSource = (CollectionViewSource)this.TryFindResource("InViewSource");
this.DirViewSource = (CollectionViewSource)this.TryFindResource("DirViewSource");
this.CorViewSource = (CollectionViewSource)this.TryFindResource("CorViewSource");
this.HoldsViewSource = (CollectionViewSource)this.TryFindResource("HoldsViewSoure");
this.LifeViewSource = (CollectionViewSource)this.TryFindResource("LifeViewSource");
this.SpecViewSource = (CollectionViewSource)this.TryFindResource("SpecViewSource");
this.ToDsViewSource = (CollectionViewSource)this.TryFindResource("ToDsViewSource");
this.RecViewSource.Source = this.RecData;
this.RecView = (ListCollectionView)(RecViewSource.View);
this.InView = (BindingListCollectionView)(InViewSource.View);
this.DirView = (BindingListCollectionView)(DirViewSource.View);
this.CorView = (BindingListCollectionView)(CorSource.View);
this.HoldsView = (BindingListCollectionView)(HoldsViewSource.View);
this.LifeView = (BindingListCollectionView)(LifeViewSource.View);
this.SpecView = (BindingListCollectionView)(SpecViewSource.View);
this.ToDsView = (BindingListCollectionView)(ToDsViewSource.View);
this.RecView.CurrentChanged += new EventHandler(RecView_CurrentChanged);
}
void RecView_CurrentChanged(object sender, EventArgs e)
{
this.InView = (BindingListCollectionView)(InViewSource.View);
this.DirView = (BindingListCollectionView)(DirViewSource.View);
this.CorView = (BindingListCollectionView)(CorViewSource.View);
this.HoldsView = (BindingListCollectionView)(HoldsViewSource.View);
this.LifeView = (BindingListCollectionView)(LifeViewSource.View);
this.SpecView = (BindingListCollectionView)(SpecViewSource.View);
this.ToDsView = (BindingListCollectionView)(ToDsViewSource.View);
}
void btnAdd_Click(object sender, RoutedEventArgs e)
{
this.RecView.AddNew();
this.RecView.CommitNew();
this.InView.AddNew();
this.InView.CommitNew();
this.DirView.AddNew();
this.DirView.CommitNew();
this.CorView.AddNew();
this.CorView.CommitNew();
this.HoldsView.AddNew();
this.HoldsView.CommitNew();
this.LifeView.AddNew();
this.LifeView.CommitNew();
this.SpecView.AddNew();
this.SpecView.CommitNew();
this.ToDsView.AddNew();
this.ToDsView.CommitNew();
}
so this is my problem exactly..... the above code for my AddRec window works to a point.
it loads, maneuvers through the records properly without being out of sync,and deletes properly but they don't AddNew right.
this is what's throwing me for a loop..... when i click my btnAdd i get a:
"Object reference not set to an instance of an object." use the "new" keyword.... ok i can live with that, i screwed up somewhere.... however if i put a breakpoint at
this.cor.view.addnew() and run it it runs fine... i get a new rec view, i get a new inview, i get a new dirview. and i can add to and save them. however the other views throw that exception.... except the corview, it just doesn't load a new corview, it's blank and not editable...???? i don't get it...
all my views are scripted the same way. the insertitem is the same for all of them.... the btnadd is the same for all of them.... why are only 3 of them working properly and 1 of them not working at all???
i even thought i screwed something up in my db, but i use this same db in another app and it works great....
thought it was the language style so i wrote the same page (used the same xaml and everything minus the namespace) in vb, and everything works right..... where did i screw up?
i'm lost, confused and baffled. any suggestions?
thanks in advance.
here's my insert statement if it helps:
protected override void InsertItem(int index, MyDAL.RecTbl item)
{
item.InTbls.AssociationChanged += new System.ComponentModel.CollectionChangeEventHandler(InTbls_AssociationChanged);
item.DirTbls.AssociationChanged += new System.ComponentModel.CollectionChangeEventHandler(DirTbls_AssociationChanged);
item.CorTbls.AssociationChanged += new System.ComponentModel.CollectionChangeEventHandler(CorTbls_AssociationChanged);
item.HoldsTbls.AssociationChanged += new System.ComponentModel.CollectionChangeEventHandler(HoldsTbls_AssociationChanged);
item.LifeTbls.AssociationChanged += new System.ComponentModel.CollectionChangeEventHandler(LifeTbls_AssociationChanged);
item.SpecTbls.AssociationChanged += new System.ComponentModel.CollectionChangeEventHandler(SpecTbls_AssociationChanged);
item.ToDTbls.AssociationChanged += new System.ComponentModel.CollectionChangeEventHandler(ToDTbls_AssociationChanged);
this.Context.AddToRecTbls(item);
base.InsertItem(index, item);
}
Oh and i'm using ado.netentity framework, entity data model. MyDAL contains the model BxEntities with the connection string etc in the app config file.
P.S. not shouting in the bold, just need to make sure these parts are reads properly.