0

I am trying to iterate through the rows in my datagrid and if a value exists in a cell the cell will be brushed Red but nothing happens and sometimes i get the error

"System.NullReferenceException: 'Object reference not set to an instance of an object.' cellContent was null."

I am trying to catch typos, if there is a typo it should be painted red.

if (mvm.IsThereAFail(temp) == true)
{
      var temp1 = mvm.ListOfRowsWhereErrorsAppear(temp);

      for (int i = 0; i == dataGrid.Items.Count; i++)
      {
           dataGrid.UpdateLayout();
           dataGrid.ScrollIntoView(dataGrid.Items[i]);
           DataGridRow row = (DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromIndex(i);

           TextBlock cellContent = dataGrid.Columns[0].GetCellContent(row) as TextBlock;

           if (temp1.Exists(x => x.Accountnumber == cellContent.Text))
           {
                  var bc = new BrushConverter();
                  row.Background = (Brush)bc.ConvertFrom("#FF230D");
                  txtBoxFail.Text += $"There is a mistake at account...: {cellContent.Text}\n";
           }
       }
   }
stuartd
  • 62,136
  • 13
  • 120
  • 150

0 Answers0