private void btnEdit_Click(object sender, EventArgs e) { try { using (DEWSRMEntities db = new DEWSRMEntities()) { int[] selRows = ((GridView)grdBranches.MainView).GetSelectedRows(); DataRowView oBranchD = (DataRowView)(((GridView)grdBranches.MainView).GetRow(selRows[0])); int nBranchID = Convert.ToInt32(oBranchD["BranchID"]); Branch oBranch = db.Branches.FirstOrDefault(p => p.BranchID == nBranchID); if (oBranch == null) { MessageBox.Show("select an item to edit", "Item not yet selected", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } fBranch frm = new fBranch(); frm.ItemChanged = RefreshList; frm.ShowDlg(oBranch, false); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnNew_Click(object sender, EventArgs e) { fBranch frm = new fBranch(); frm.ItemChanged = RefreshList; frm.ShowDlg(new Branch(), true); }