How can I locate a field in a Silverlight 3 DataGrid?
I need to locate a cell/column in a Silverlight 3 DataGrid so that I can call UpdateSource on it. How can I do that?
This is why, in case you're interested:
I have a DataGrid in a Silverlight 3 app which displays objects which are decorated with DataAnnotations attributes such as [Required], for validation purposes. I'm populating the DataGrid from an imported CSV file. The imported rows will be invalid because the CSV doesn't contain all of the Required fields.
Validation works, if the user edits the fields in the datagrid or when I call 开发者_如何学Csubmit (it's a WCF RIA Services app). What I'd like to do it trigger validation as soon as the datagrid is loaded. From lots of reading, it seems there's no built-in way to do this.
I've figured that if I can locate the field in the first row in the datagrid and call UpdateSource(), I'll trigger a validation error. How can I navigate into a manually-defined datagrid?
DataGridFieldName.Items gives you access to the objects bound to the DataGrid. You can trigger validation on this item by manually calling Validator.ValidateObject.
var firstRowOfDataGrid = dataGrid.Items[0];
ValidationContext validationContext = new ValidationContext(firstRowOfDataGrid, null, null);
Validator.ValidateObject(this, validationContext);
I dont know if this solves your scenario ,but its worth a try.
Validator on MSDN
http://msdn.microsoft.com/en-us/library/dd382100(VS.100).aspx
Have you tried with:
Validator..::.ValidateObject Method (Object, ValidationContext)
Have you tried using FindName("Name")
http://msdn.microsoft.com/en-us/library/bb979952%28VS.95%29.aspx
精彩评论