Skip to content

DevExpress-Examples/winforms-grid-highlight-modified-cells

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WinForms Data Grid - Highlight modified cells

Note

In v19.1+, you can use the FormatConditionRuleDataUpdate class to highlight a cell with a custom icon and/or appearance settings for a limited time when a cell value changes in GridView, BandedGridView, and AdvBandedGridView. Example

This example shows how to highlight modified cells.

Once the user changes a cell's value, the cell is added to the modifiedCells collection:

List<GridCell> modifiedCells = new List<GridCell>();
void gridView1_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e) {
    if (!CellExists(gridView1.GetDataSourceRowIndex(e.RowHandle), e.Column)){
        modifiedCells.Add(new GridCell(gridView1.GetDataSourceRowIndex(e.RowHandle), e.Column));
	}
}

The RowCellStyle event is handled to customize the appearance (background and foreground colors) of modified cells:

void gridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e) {
    if (CellExists(gridView1.GetDataSourceRowIndex(e.RowHandle), e.Column)) {
        e.Appearance.BackColor = Color.ForestGreen;
        e.Appearance.BackColor2 = Color.LimeGreen;
        e.Appearance.Font = new Font(e.Appearance.Font, FontStyle.Bold);
	}
}
bool CellExists(int sourceRowIndex, GridColumn col) {
    GridCell existingCell = modifiedCells.Where(c => c.Column == col && c.RowHandle == sourceRowIndex).FirstOrDefault();
    return existingCell != null;
}

Files to Review

Documentation

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)