I am trying to change the Background of some errorneous data containing cells in a WPF DataGrid by using this code:
DataGridRow gridRow = dgInventory.ItemContainerGenerator.ContainerFromIndex(0) as DataGridRow;
DataGridCell cell = dgInventory.Columns[1].GetCellContent(gridRow).Parent as DataGridCell;
cell.Background = Brushes.Gray;
gridRow.IsSelected = true;
gridRow.Focus();
However, upon doing this, the above change of background-color change is occuring to cells in the same column, periodically after every 14 (aprox.) rows as I scroll down the DataGrid. It is only intended to modify the Background of a single row. Can someone please provide a fix to this problem? Thanks in advance.
Try using this:
<DataGrid Name="SimpleDataGrid" ScrollViewer.CanContentScroll="False" ... />
for scrolls in terms of physical units. It DataGrid CanContentScroll it is enabled by default.
For more information see MSDN.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With