private void bindingNavigatorAddNewItem1_Click(object sender, EventArgs e) { Category category = (Category)categoryDataGridView.SelectedRows[0].DataBoundItem; Product newProduct = new Product { CategoryID = category.CategoryID }; using (var db2 = new ProdContext()) { db2.Products.Add(newProduct); db2.SaveChanges(); } db.Products.Attach(newProduct); productBindingSource.ResetBindings(false); }
private void onLoad(object sender, EventArgs e) { db = new ProdContext(); db.Categories.Load(); this.categoryBindingSource.DataSource = db.Categories.Local.ToBindingList(); }