private void btnNew_Click(object sender, EventArgs e) { _Item = null; tbName.Text = ""; tbName.ReadOnly = false; btnSave.Visible = true; btnCancel.Visible = true; btnNew.Visible = false; dgItems.Enabled = false; }
private void dgItems_CellContentClick(object sender, DataGridViewCellEventArgs e) { var senderGrid = (DataGridView)sender; if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.RowIndex >= 0) { _Item = senderGrid.Rows[e.RowIndex].DataBoundItem as ManagementPackTOCItem; if (_Item != null) { if (e.ColumnIndex == 0) { EditItem(); } else { DeleteItem(); } } } }
private void btnSave_Click(object sender, EventArgs e) { if (String.IsNullOrWhiteSpace(tbName.Text)) { Controller.HandleError("Name is required", "Validation Error"); return; } if (_Item == null) { _Item = new ManagementPackTOCItem(); dataContext.ManagementPackTOCItemSet.Add(_Item); } _Item.Description = tbName.Text; try { bool isNew = _Item.id == 0; dataContext.SaveChanges(); if (isNew) { _Data.Insert(0, _Item); } BindDataGrid(); GotoReadOnly(); } catch (DbUpdateException ex) { Controller.HandleError("Possible duplicate record detected", "Database Error"); } catch (Exception ex2) { Controller.HandleError(ex2.Message); } }