I am displaying two datatables (let’s call them left and right) in two datagrids and it works. However what I want to do is to allows users compare two rows (left and right) based on the selection and change the background when the cells are different.
Sample:
Left
|A|B|C|
|1|2|3|
|1|2|3|
|1|2|3|
Right
|A|B|C|
|1|2|4|
|1|2|3|
|1|2|3|
In XAML my Datagrids look like:<DataGrid Grid.Column="0" x:Name="leftData" HorizontalAlignment="Stretch" >
</DataGrid>
And in Code I am binding the datagrid to the DataTable:
TableRows = new DataTable();
leftData.ItemsSource = TableRows;
When the user selects the first row on the left and right, the cells on column C should be marked with a red background.
How is the better approach for doing that in WPF? Is it possible to do that with DataGrid in WPF?
Finally I found the solution. The DataGrid control does not offer a way to get a DataGridCell, however it is possible to get it from the DataGrid control by using the VisualTreeHelper in order to get the DataGridCellsPresenter and from the presenter it is possible to get the DataGridCell.
More information and the code can be found here:
http://techiethings.blogspot.ch/2010/05/get-wpf-datagrid-row-and-cell.html