private void btnAdd_Click(object sender, EventArgs e) { btnEdit.Visible = false; frmSPPAddItem frm = new frmSPPAddItem { StartPosition = FormStartPosition.CenterScreen }; frm.ShowDialog(); if (frmSPPAddItem.itemAdded) { //add data to datarow //add datarow to table DataRow dt_Row = dt_Source.NewRow(); dt_Row[header_Size] = frmSPPAddItem.item_Size; dt_Row[header_Unit] = "MM"; dt_Row[header_Type] = frmSPPAddItem.item_Type; dt_Row[header_Code] = frmSPPAddItem.item_Code; dt_Row[header_Target_Pcs] = frmSPPAddItem.item_Target_Pcs; dt_Row[header_Target_Bag] = frmSPPAddItem.item_Target_Bags; dt_Source.Rows.Add(dt_Row); //add data to target list ShowTargetList(); //calculate material qty ShowMaterialList(); frmSPPAddItem.itemAdded = false; } }
private void dgvTargetItem_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { //get item info DataTable dt = (DataTable)dgvTargetItem.DataSource; int rowIndex = dgvTargetItem.CurrentRow.Index; //string code, string type, string size, string unit string code = dt.Rows[rowIndex][header_Code].ToString(); string type = dt.Rows[rowIndex][header_Type].ToString(); string size = dt.Rows[rowIndex][header_Size].ToString(); string unit = dt.Rows[rowIndex][header_Unit].ToString(); string targetPcs = dt_Source.Rows[rowIndex][header_Target_Pcs].ToString(); if (rowIndex >= 0) { frmSPPAddItem frm = new frmSPPAddItem(code, type, size, unit, targetPcs) { StartPosition = FormStartPosition.CenterScreen }; frm.ShowDialog(); if (frmSPPAddItem.itemEdited) { btnEdit.Visible = false; //add data to datarow //add datarow to table dt_Source.Rows.RemoveAt(rowIndex); DataRow dt_Row = dt_Source.NewRow(); dt_Row[header_Size] = frmSPPAddItem.item_Size; dt_Row[header_Unit] = "MM"; dt_Row[header_Type] = frmSPPAddItem.item_Type; dt_Row[header_Code] = frmSPPAddItem.item_Code; dt_Row[header_Target_Pcs] = frmSPPAddItem.item_Target_Pcs; dt_Row[header_Target_Bag] = frmSPPAddItem.item_Target_Bags; dt_Source.Rows.Add(dt_Row); //add data to target list ShowTargetList(); //calculate material qty ShowMaterialList(); frmSPPAddItem.itemEdited = false; } else if (frmSPPAddItem.itemRemoved) { btnEdit.Visible = false; dt_Source.Rows.RemoveAt(rowIndex); dgvTargetItem.DataSource = dt_Source; //add data to target list ShowTargetList(); //calculate material qty ShowMaterialList(); frmSPPAddItem.itemRemoved = false; } } else { MessageBox.Show("Please select a row!"); } }