private void btedit_Click(object sender, EventArgs e) { if (gvunit.SelectedRows.Count == 0) { MessageBox.Show("Tidak ada kemasan yang akan diubah"); } else { var selectedRowId = (int)gvunit.SelectedRows[0].Cells["id"].Value; var selectedUnit = ListUnits.FirstOrDefault(x => x.unitid == selectedRowId); if (selectedRowId == 1) { MessageBox.Show("Anda tidak dibenarkan mengubah kemasan Lain-Lain"); } else if (selectedUnit != null) { var form = new ManageUnit(); form.userdata = userdata; form.Editmode = true; form.UnitData = selectedUnit; form.ShowDialog(); LoadData(); foreach (DataGridViewRow row in gvunit.Rows) { if (((int)row.Cells["id"].Value) == selectedRowId) { gvunit.Rows[row.Index].Selected = true; break; } } } } }
private void btadd_Click(object sender, EventArgs e) { int oritotalrow = gvunit.Rows.Count; var form = new ManageUnit(); form.userdata = userdata; form.ShowDialog(); LoadData(); int newtotalrow = gvunit.Rows.Count; if (oritotalrow != newtotalrow) { var newUnit = new UnitColumns(); newUnit = unitRepository.GetByAny(1); int newId = newUnit.unitid; foreach (DataGridViewRow row in gvunit.Rows) { if (((int)row.Cells["id"].Value) == newId) { gvunit.Rows[row.Index].Selected = true; break; } } } }