0

I've tried below but it would change whole datagrid's rows background color.

 foreach (DataRowView rowww in ResExDataGrid.Items)
  {
    foreach (DataRowView rowView in ResAcDataGrid.Items)
     {
      string textEX = rowww.Row.ItemArray[1].ToString();
      string textAC = rowww.Row.ItemArray[1].ToString();
      // if would set for your row if text mathches
      if (!(textEX == textAC) )
       {
         //changes whole data grid rows background
          ResExDataGrid.RowBackground = Brushes.Red;
       }
   }
}

this is with key value pair. This is how the program flow should be.

    foreach(KeyValuePair<string,string> dg in DataGrid.Items)
    {
      foreach(KeyValuePair<string,string> dg2 in DataGrid.Items)
      {
       foreach (DataRowView dataRow in DataGrid.Row)
       {
        for (int i = 0; i < DataGrid.Columns.Count; i++)
        {
         if(dg.Value != dg2.Value)
             dataRow.columns[i].Style.BackColor = Color.Red;
        }
       }
      }
    }

Help is appreciated.

  • Do you need Cell Background? – st_stefanov Oct 30 '19 at 07:31
  • Yes. if cell value in both datagrids doesn't match that cell background should change color. Thanks – Jaswanth Kiran Oct 30 '19 at 07:33
  • 2
    Try this: https://stackoverflow.com/questions/5549617/change-datagrid-cell-colour-based-on-values And this: https://social.msdn.microsoft.com/Forums/vstudio/en-US/8e598d5e-2e64-476d-941b-546a821aaa88/wpf-datagrid-change-single-cell-background?forum=wpf – st_stefanov Oct 30 '19 at 07:50

1 Answers1

0
for (int i = 0; i < FirstDataGridItemsSourceList.Count; i++)
{
  if (FirstDataGridItemsSourceList[i].Data != SecondDataGridItemsSourceList[i].Data)
  {
    FirstDataGridItemsSourceList[i].ColorChange = SecondDataGridItemsSourceList[i].ColorChange = true;
  }
}

and then use a datatrigger and use binding to ColorChange property. PS- this only works if both datagrid items list contain same number of index.