Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking If Any WPF DataGrid Cell Has Error

I have validation set up on the cells and it works as expected (placing a red highlight around the textbox and adding a tooltip with the error). However, If I try to access Validation.GetHasError(TheGrid) where TheGrid is my DataGrid, it is always false. Does anyone know how to check if ANY cells in the DataGrid have errors?

I want to do this so I can disable saving if there are errors.

like image 283
KrisTrip Avatar asked Aug 10 '11 20:08

KrisTrip


1 Answers

You might run into problems with virtualization with this but you probably do have to look at the containers:

var errors = (from c in
                  (from object i in _myGrid.ItemsSource
                   select _myGrid.ItemContainerGenerator.ContainerFromItem(i))
              where c != null
              select Validation.GetHasError(c))
             .FirstOrDefault(x => x);
if (errors)
{
    //There be errors
}
like image 108
H.B. Avatar answered Oct 20 '22 14:10

H.B.