In the project that I am working on, I need to highlight differences, so in col1 I am displaying the source data and in col2 I am showing the target data. When the cell value in cell1 is not equal to cell2, then I need to color cell 2 to show that there is a difference. In my small sample app, I am using CellLoaded event and the code below. This kind of works but from time to time the wrong cells are highlighted. Also the approach to handle this use case seems kind of brute force and I was wondering if there is a better way to handle this.
Below is a sample piece of code that I have been using in the test
private void RowDataGrid_CellLoaded(object sender, CellEventArgs e)
{
GridViewCell tgtFld = e.Cell as GridViewCell;
if (tgtFld != null)
{
if (e.Cell.Column.UniqueName.ToUpper().EndsWith("_T"))
{
string fieldName = e.Cell.Column.UniqueName.ToUpper().Replace("_T", "_S");
foreach (var item in e.Cell.ParentRow.Cells)
{
if (item.Column.UniqueName.ToUpper() == fieldName)
{
if (((GridViewCell)item).Value != tgtFld.Value)
{
tgtFld.Background = new SolidColorBrush(Colors.Green);
}
break;
}
}
}
}
}
Below is a sample piece of code that I have been using in the test
private void RowDataGrid_CellLoaded(object sender, CellEventArgs e)
{
GridViewCell tgtFld = e.Cell as GridViewCell;
if (tgtFld != null)
{
if (e.Cell.Column.UniqueName.ToUpper().EndsWith("_T"))
{
string fieldName = e.Cell.Column.UniqueName.ToUpper().Replace("_T", "_S");
foreach (var item in e.Cell.ParentRow.Cells)
{
if (item.Column.UniqueName.ToUpper() == fieldName)
{
if (((GridViewCell)item).Value != tgtFld.Value)
{
tgtFld.Background = new SolidColorBrush(Colors.Green);
}
break;
}
}
}
}
}