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 .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.