I want to achieve a pretty simple task, but none of the solutions here on SO or otherwise found have helped me so far:
I have a WPF DataGrid, which is b
OK, I've worked it out. The following does what I want:
public static DataGridRow GetRow(DataGrid grid, int index)
{
DataGridRow row = (DataGridRow)grid.ItemContainerGenerator.ContainerFromIndex(index);
if (row == null)
{
// May be virtualized, bring into view and try again.
grid.UpdateLayout();
grid.ScrollIntoView(grid.Items[index]);
row = (DataGridRow)grid.ItemContainerGenerator.ContainerFromIndex(index);
}
return row;
}
In the code for my "OK" button I do:
for (int i = 0; i < dgvData.Items.Count; i++)
{
DataGridRow row = GetRow(dgvData, i);
if (row != null && Validation.GetHasError(row))
{
hasDataGridErrors = true;
break;
}
}