private void ShowDreamList() { var db = new DreamDBEntities1(); this.dtManage.DataSource = db.DreamLists.ToList(); this.dtManage.Columns["idDream"].Visible = false; this.dtManage.Columns["status"].Visible = false; this.dtHome.DataSource = db.DreamLists.ToList(); this.dtHome.Columns["idDream"].Visible = false; this.dtHome.Columns["splitphase"].Visible = false; this.dtHome.Columns["DateCreated"].Visible = false; this.dtHome.Columns["DateExpired"].Visible = false; }
private void btnDelete_Click(object sender, EventArgs e) { this.dtManage.SelectionMode = DataGridViewSelectionMode.FullRowSelect; var db = new DreamDBEntities1(); for (int i = 0; i < this.dtManage.SelectedRows.Count; i++) { var row = this.dtManage.SelectedRows[i]; var item = (DreamList)row.DataBoundItem; try { var delete = db.DreamLists.Find(item.idDream); db.DreamLists.Remove(delete); db.SaveChanges(); this.ShowDreamList(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }