views:

226

answers:

3

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 submit (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?

A: 

Have you tried using FindName("Name")

http://msdn.microsoft.com/en-us/library/bb979952%28VS.95%29.aspx

Detroitpro
No, that doesn't work. I've tried it against the DataGrid and against a specific Row but it returns null in both cases.
ssg31415926
+1  A: 

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

Phani Raj
What is DataGridFieldName? I can't find it on MSDN.
ssg31415926
+1  A: 

Have you tried with:

Validator..::.ValidateObject Method (Object, ValidationContext)

Adnan