I am using a common Silverlight DataGrid to display results from a search. The "schema" of the search can vary from query to query.
To accommodate this, I am trying to dynamically populate the DataGrid. I can set explicitly set the columns, but I am having trouble setting the ItemSource. All of the MSDN examples set the ItemSource to a collection with a strong type (e.g. a Custom type with public properties matching the schema). The DataGrid then uses reflection to scour the strong type for public properties that will match the columns.
Since my search results are dynamic, I cannot create a strong type to represent what comes back. Can I not just give the DataGrid an arbitrary list of objects so long as the number of objects in each list matches the number of columns? Anyone know if this is possible?
I would like to do something similar to this:
List<List<object>> myResults = <voodoo that populates the result list>
myDataGrid.ItemsSource = myResults;
The following article gets me close to what I want: http://blogs.msdn.com/b/scmorris/archive/2008/04/14/defining-silverlight-datagrid-columns-at-runtime.aspx
Essentially, you have to have a bindable property. You can't just create rows based on an arbitrary list of items. I stumbled upon a couple of open source projects that solve this problem by using reflection to build CLR types at runtime and then bind to those types.