/* CopyRow_Click * insert a copy of the current row at the next row at the Matrix Script */ public DataGridViewRow CloneWithValues(DataGridViewRow row) { DataGridViewRow clonedRow = (DataGridViewRow)row.Clone(); for (Int32 index = 0; index < row.Cells.Count; index++) { clonedRow.Cells[index].Value = row.Cells[index].Value; } return clonedRow; }
public DataGridViewRow this [int index] { get { // Accessing a System.Windows.Forms.DataGridViewRow with this indexer causes the row to become unshared. // To keep the row shared, use the System.Windows.Forms.DataGridViewRowCollection.SharedRow method. // For more information, see Best Practices for Scaling the Windows Forms DataGridView Control. DataGridViewRow row = (DataGridViewRow)list [index]; if (row.Index == -1) { row = (DataGridViewRow)row.Clone(); row.SetIndex(index); list [index] = row; } return(row); } }
public DataGridViewRow CopyRowWithValues(DataGridView Gridview, DataGridViewRow row, string[] ColumnNameTobeIgnoreValues) { DataGridViewRow copiedRow = (DataGridViewRow)row.Clone(); for (Int32 index = 0; index < row.Cells.Count; index++) { string columnName = Gridview.Columns[index].Name.ToString().Trim(); if (ColumnNameTobeIgnoreValues.Contains(columnName) == false) { copiedRow.Cells[index].Value = row.Cells[index].Value; } } return copiedRow; }
/// <summary> /// Clones the row. /// </summary> /// <param name="row">The Data Grid View row.</param> /// <returns>Data Grid View Row</returns> protected DataGridViewRow CloneRow(DataGridViewRow row) { DataGridViewRow newRow = row.Clone() as DataGridViewRow; newRow.Cells[0].Value = new Bitmap(row.Cells[0].Value as Bitmap); newRow.Cells[1].Value = string.Copy(row.Cells[1].Value as string); return newRow; }
private int AddDuplicateRow(DataGridViewRow rowTemplate, bool newRow) { DataGridViewRow dataGridViewRow = (DataGridViewRow) rowTemplate.Clone(); dataGridViewRow.StateInternal = DataGridViewElementStates.None; dataGridViewRow.DataGridViewInternal = this.dataGridView; DataGridViewCellCollection cells = dataGridViewRow.Cells; int num = 0; foreach (DataGridViewCell cell in cells) { if (newRow) { cell.Value = cell.DefaultNewRowValue; } cell.DataGridViewInternal = this.dataGridView; cell.OwningColumnInternal = this.DataGridView.Columns[num]; num++; } DataGridViewElementStates rowState = rowTemplate.State & ~(DataGridViewElementStates.Selected | DataGridViewElementStates.Displayed); if (dataGridViewRow.HasHeaderCell) { dataGridViewRow.HeaderCell.DataGridViewInternal = this.dataGridView; dataGridViewRow.HeaderCell.OwningRowInternal = dataGridViewRow; } this.DataGridView.OnAddingRow(dataGridViewRow, rowState, true); this.rowStates.Add(rowState); return this.SharedList.Add(dataGridViewRow); }
private void InsertDuplicateRow(int indexDestination, DataGridViewRow rowTemplate, bool firstInsertion, ref Point newCurrentCell) { DataGridViewRow dataGridViewRow = (DataGridViewRow) rowTemplate.Clone(); dataGridViewRow.StateInternal = DataGridViewElementStates.None; dataGridViewRow.DataGridViewInternal = this.dataGridView; DataGridViewCellCollection cells = dataGridViewRow.Cells; int num = 0; foreach (DataGridViewCell cell in cells) { cell.DataGridViewInternal = this.dataGridView; cell.OwningColumnInternal = this.DataGridView.Columns[num]; num++; } DataGridViewElementStates rowState = rowTemplate.State & ~(DataGridViewElementStates.Selected | DataGridViewElementStates.Displayed); if (dataGridViewRow.HasHeaderCell) { dataGridViewRow.HeaderCell.DataGridViewInternal = this.dataGridView; dataGridViewRow.HeaderCell.OwningRowInternal = dataGridViewRow; } this.DataGridView.OnInsertingRow(indexDestination, dataGridViewRow, rowState, ref newCurrentCell, firstInsertion, 1, false); this.SharedList.Insert(indexDestination, dataGridViewRow); this.rowStates.Insert(indexDestination, rowState); }
private void SetProductDetail(DataGridViewRow gRow, double productID) { bool isDuplicate = false; double quantity = 0; if (gRow.Cells[indexQTY].Value == null) gRow.Cells[indexQTY].Value = 1; if (gRow.Cells[indexQTY].Value.ToString().Trim() == "") gRow.Cells[indexQTY].Value = 1; quantity = Convert.ToDouble(gRow.Cells[indexQTY].Value); foreach (DataGridViewRow cRow in this.grvSupport.Rows) { if (!cRow.IsNewRow) { if (cRow.Index != gRow.Index && cRow.Cells[indexPRODUCT].Value.ToString() == productID.ToString()) { cRow.Cells[indexQTY].Value = (Convert.ToDouble(cRow.Cells[indexQTY].Value) + quantity).ToString(Constz.IntFormat); isDuplicate = true; break; } } } if (isDuplicate) { if (gRow.IsNewRow) { for (int i = 0; i < this.grvSupport.Columns.Count; ++i) { gRow.Cells[i].Value = DBNull.Value; } } else { this.grvSupport.EndEdit(); this.grvSupport.Rows.Remove(gRow); } } else { ProductSaleData data = SaleObj.GetProductPromotion(productID, Appz.CurrentUserData.Warehouse); gRow.Cells[indexPRODUCT].Value = data.PRODUCT; gRow.Cells[indexUNIT].Value = data.UNIT.ToString(); gRow.Cells[indexBARCODE].Value = data.BARCODE; gRow.Cells[indexNAME].Value = data.PRODUCTNAME; gRow.Cells[indexUNITNAME].Value = data.UNITNAME; gRow.Cells[indexPRICE].Value = SaleObj.CalculateUnitPrice(data.UNITPRICE, Convert.ToDouble(this.txtVat.Text == "" ? "0" : this.txtVat.Text), data.ISVAT); gRow.Cells[indexNORMALDISCOUNT].Value = data.DISCOUNT.ToString(); gRow.Cells[indexNETPRICE].Value = SaleObj.CalcucateProductTotalItem(Convert.ToDouble(gRow.Cells[indexPRICE].Value), Convert.ToDouble(gRow.Cells[indexQTY].Value), data.DISCOUNT); gRow.Cells[indexISVAT].Value = (data.ISVAT == Constz.VAT.Included.Code); if (gRow.IsNewRow) { SetDataGridViewImageColumnCellStyle(); DataGridViewRow newRow = (DataGridViewRow)gRow.Clone(); newRow.Cells[indexORDERNO].Value = this.grvSupport.Rows.Count.ToString(); newRow.Cells[indexBARCODE].Value = gRow.Cells[indexBARCODE].Value; newRow.Cells[indexNORMALDISCOUNT].Value = gRow.Cells[indexNORMALDISCOUNT].Value; newRow.Cells[indexISVAT].Value = gRow.Cells[indexISVAT].Value; newRow.Cells[indexNAME].Value = gRow.Cells[indexNAME].Value; newRow.Cells[indexNETPRICE].Value = gRow.Cells[indexNETPRICE].Value; newRow.Cells[indexPRICE].Value = gRow.Cells[indexPRICE].Value; newRow.Cells[indexPRODUCT].Value = gRow.Cells[indexPRODUCT].Value; newRow.Cells[indexQTY].Value = gRow.Cells[indexQTY].Value; newRow.Cells[indexUNIT].Value = gRow.Cells[indexUNIT].Value; newRow.Cells[indexUNITNAME].Value = gRow.Cells[indexUNITNAME].Value; for (int i = 0; i < this.grvSupport.Columns.Count; ++i) { gRow.Cells[i].Value = DBNull.Value; } if (!Validate(newRow)) return; this.grvSupport.Rows.Add(newRow);// } } CalculateGrandTotal(); }
private static DataGridViewRow CloneRow(DataGridViewRow row) { var clone = (DataGridViewRow)row.Clone(); for (int i = 0; i < row.Cells.Count; i++) { clone.Cells[i].Value = row.Cells[i].Value; } return clone; }
private void SetProductDetail(DataGridViewRow gRow, double productID) { bool isDuplicate = false; double quantity = 0; if (gRow.Cells[indexQTY].Value == null) gRow.Cells[indexQTY].Value = 1; if (gRow.Cells[indexQTY].Value.ToString().Trim() == "") gRow.Cells[indexQTY].Value = 1; quantity = Convert.ToDouble(gRow.Cells[indexQTY].Value); foreach (DataGridViewRow cRow in this.grvStockin.Rows) { if (!cRow.IsNewRow) { if (cRow.Index != gRow.Index && cRow.Cells[indexPRODUCT].Value.ToString() == productID.ToString()) { cRow.Cells[indexQTY].Value = (Convert.ToDouble(cRow.Cells[indexQTY].Value) + quantity).ToString(Constz.IntFormat); isDuplicate = true; break; } } } if (isDuplicate) { if (gRow.IsNewRow) { for (int i = 0; i < this.grvStockin.Columns.Count; ++i) { gRow.Cells[i].Value = DBNull.Value; } } else { this.grvStockin.EndEdit(); this.grvStockin.Rows.Remove(gRow); } } else { ProductSaleData data = SaleObj.GetProductPromotion(productID, 3); gRow.Cells[indexPRODUCT].Value = data.PRODUCT; gRow.Cells[indexUNIT].Value = data.UNIT.ToString(); gRow.Cells[indexBARCODE].Value = data.BARCODE; gRow.Cells[indexNAME].Value = data.PRODUCTNAME; gRow.Cells[indexUNITNAME].Value = data.UNITNAME; gRow.Cells[indexPRICE].Value = data.UNITPRICE; gRow.Cells[indexNETPRICE].Value = data.UNITPRICE * Convert.ToDouble(gRow.Cells[indexQTY].Value); if (gRow.IsNewRow) { SetDataGridViewImageColumnCellStyle(); DataGridViewRow newRow = (DataGridViewRow)gRow.Clone(); newRow.Cells[indexORDERNO].Value = this.grvStockin.Rows.Count.ToString(); newRow.Cells[indexBARCODE].Value = gRow.Cells[indexBARCODE].Value; newRow.Cells[indexNAME].Value = gRow.Cells[indexNAME].Value; newRow.Cells[indexNETPRICE].Value = gRow.Cells[indexNETPRICE].Value; newRow.Cells[indexPRICE].Value = gRow.Cells[indexPRICE].Value; newRow.Cells[indexPRODUCT].Value = gRow.Cells[indexPRODUCT].Value; newRow.Cells[indexQTY].Value = gRow.Cells[indexQTY].Value; newRow.Cells[indexUNIT].Value = gRow.Cells[indexUNIT].Value; newRow.Cells[indexUNITNAME].Value = gRow.Cells[indexUNITNAME].Value; for (int i = 0; i < this.grvStockin.Columns.Count; ++i) { gRow.Cells[i].Value = DBNull.Value; } if (!Validate(newRow)) return; this.grvStockin.Rows.Add(newRow);// } } Calculate(); }
private int AddDuplicateRow(DataGridViewRow rowTemplate, bool newRow) { Debug.Assert(this.DataGridView != null); DataGridViewRow dataGridViewRow = (DataGridViewRow) rowTemplate.Clone(); dataGridViewRow.StateInternal = DataGridViewElementStates.None; dataGridViewRow.DataGridViewInternal = this.dataGridView; DataGridViewCellCollection dgvcc = dataGridViewRow.Cells; int columnIndex = 0; foreach (DataGridViewCell dataGridViewCell in dgvcc) { if (newRow) { dataGridViewCell.Value = dataGridViewCell.DefaultNewRowValue; } dataGridViewCell.DataGridViewInternal = this.dataGridView; dataGridViewCell.OwningColumnInternal = this.DataGridView.Columns[columnIndex]; columnIndex++; } DataGridViewElementStates rowState = rowTemplate.State & ~(DataGridViewElementStates.Selected | DataGridViewElementStates.Displayed); if (dataGridViewRow.HasHeaderCell) { dataGridViewRow.HeaderCell.DataGridViewInternal = this.dataGridView; dataGridViewRow.HeaderCell.OwningRowInternal = dataGridViewRow; } this.DataGridView.OnAddingRow(dataGridViewRow, rowState, true /*checkFrozenState*/); // will throw an exception if the addition is illegal #if DEBUG this.DataGridView.dataStoreAccessAllowed = false; this.cachedRowHeightsAccessAllowed = false; this.cachedRowCountsAccessAllowed = false; #endif Debug.Assert(dataGridViewRow.Index == -1); this.rowStates.Add(rowState); return this.SharedList.Add(dataGridViewRow); }
private void InsertDuplicateRow(int indexDestination, DataGridViewRow rowTemplate, bool firstInsertion, ref Point newCurrentCell) { Debug.Assert(this.DataGridView != null); DataGridViewRow dataGridViewRow = (DataGridViewRow) rowTemplate.Clone(); dataGridViewRow.StateInternal = DataGridViewElementStates.None; dataGridViewRow.DataGridViewInternal = this.dataGridView; DataGridViewCellCollection dgvcc = dataGridViewRow.Cells; int columnIndex = 0; foreach (DataGridViewCell dataGridViewCell in dgvcc) { dataGridViewCell.DataGridViewInternal = this.dataGridView; dataGridViewCell.OwningColumnInternal = this.DataGridView.Columns[columnIndex]; columnIndex++; } DataGridViewElementStates rowState = rowTemplate.State & ~(DataGridViewElementStates.Selected | DataGridViewElementStates.Displayed); if (dataGridViewRow.HasHeaderCell) { dataGridViewRow.HeaderCell.DataGridViewInternal = this.dataGridView; dataGridViewRow.HeaderCell.OwningRowInternal = dataGridViewRow; } this.DataGridView.OnInsertingRow(indexDestination, dataGridViewRow, rowState, ref newCurrentCell, firstInsertion, 1, false /*force*/); // will throw an exception if the insertion is illegal Debug.Assert(dataGridViewRow.Index == -1); this.SharedList.Insert(indexDestination, dataGridViewRow); this.rowStates.Insert(indexDestination, rowState); Debug.Assert(this.rowStates.Count == this.SharedList.Count); #if DEBUG this.DataGridView.dataStoreAccessAllowed = false; this.cachedRowHeightsAccessAllowed = false; this.cachedRowCountsAccessAllowed = false; #endif }
public static void CopySelectedRow(DataGridViewPersistent dgv_org, DataGridViewRow row) { DataGridViewPersistent dgv_copy = new DataGridViewPersistent(); try { if (dgv_copy.Columns.Count == 0) { foreach (DataGridViewColumn dgvc in dgv_org.Columns) { dgv_copy.Columns.Add(dgvc.Clone() as DataGridViewColumn); } } row = (DataGridViewRow)row.Clone(); row.Cells[0].Value = row.Cells[0].Value; dgv_copy.Rows.Add(row); dgv_copy.AllowUserToAddRows = false; dgv_copy.Refresh(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }