/// <summary> /// Reflects changes in Excel worksheet if this row has just been added to a <see cref="MySqlDataTable"/>. /// </summary> private void ReflectChangesForAddedRow() { if (ExcelRange == null) { return; } ExcelRange.SetInteriorColor(ExcelUtilities.UncommittedCellsOleColor); ExcelModifiedRangesList.Add(ExcelRange); }
/// <summary> /// Reflects changes in Excel worksheet if this row has just been modified. /// </summary> private void ReflectChangesForModifiedRow() { if (RowState == DataRowState.Added && ExcelRange != null) { // A recently added row's value is being modified, we just need to re-paint the whole "added" row. ExcelRange.SetInteriorColor(ExcelUtilities.UncommittedCellsOleColor); } if (RowState != DataRowState.Modified) { return; } if (ExcelRange != null) { ExcelModifiedRangesList.Clear(); } ChangedColumnNames.Clear(); // Check column by column for data changes, set related Excel cells color accordingly. for (int colIndex = 0; colIndex < Table.Columns.Count; colIndex++) { ExcelInterop.Range columnCell = ExcelRange != null ? ExcelRange.Cells[1, colIndex + 1] : null; bool originalAndModifiedIdentical = this[colIndex].Equals(this[colIndex, DataRowVersion.Original]); if (!originalAndModifiedIdentical) { if (columnCell != null) { ExcelModifiedRangesList.Add(columnCell); } ChangedColumnNames.Add(Table.Columns[colIndex].ColumnName); } if (columnCell == null) { continue; } var cellColor = originalAndModifiedIdentical ? _excelRangePreviousColors[colIndex] : ExcelUtilities.UncommittedCellsOleColor; columnCell.SetInteriorColor(cellColor); } // If the row resulted with no modifications (maybe some values set back to their original values by the user) then undo changes. if (ChangedColumnNames.Count == 0) { RejectChanges(); } }