Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing a cell in a row of a DataGrid(WPF) is changing cells in rows below

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.

like image 200
Nishanth Reddy Avatar asked Oct 21 '22 04:10

Nishanth Reddy


1 Answers

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.

like image 85
Anatoliy Nikolaev Avatar answered Oct 30 '22 04:10

Anatoliy Nikolaev