How do I programmatically insert rows into a Silverlight DataGrid without binding?
Posted
by j0rd4n
on Stack Overflow
See other posts from Stack Overflow
or by j0rd4n
Published on 2010-06-07T22:04:55Z
Indexed on
2010/06/07
23:32 UTC
Read the original article
Hit count: 275
datagrid
|silverlight-4.0
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;
© Stack Overflow or respective owner