0

I need to do the following with a DataGrid. E.g.

Col A       Col B
1           A           
2           B
3           C
4           D

For instance where Col A = 3. I then want to change the background cell.Background = some color where row 3 intersects Col B. I would be passing in the value for Col A and column name dynamically. I am returning the cell values from a DataTable where the DataGrid is bound to a defaultview of the DataTable. Col A is the unique key.

  • can you give more explanation of what are you trying to achieve?Do you want to change the color of a cell? – Fatema Feb 14 '12 at 06:51
  • I am comparing two DataTables that are bound to DataGrids (same table structure). I am comparing cell by cell for differences. I want to change the cell color on cells that have differences in the DataGrid; not the entire row. I am able to identify the cells in the DataTable's with differences; then based on the unique key I want to hit that row then intersect on the column header and only update that cell where the row and column header match. –  Feb 14 '12 at 07:16
  • Or is there any way to highlight the cell in the DataTable and refresh the view on the dataGrid? I don't see any properties on the DataTable to handle this. DT.Rows[i]["Col_ID"] –  Feb 14 '12 at 17:27

2 Answers2

0

if you wanna change your cell style - use the cell style and Style.DataTrigger. you just have to make sure that the data you need is anywhere in the DataRow.

blindmeis
  • 22,175
  • 7
  • 55
  • 74
0

Found a solution with a single line of code to pragmatically set the current cell based on the items and column index for anyone else who may be looking for a solution to this as well.

In the XAML ensure the SelectionUnit is set to cell. Then:

dg.CurrentCell = new DataGridCellInfo(dg.Items[0],dg.Columns[0]);
DaveShaw
  • 52,123
  • 16
  • 112
  • 141