Question

I'm trying to read a table from an Excel file (.xls) and display it in a DataGrid. The table has unknown dimensions and each column has values of one unknown type (string, double or int).

I access the file via COM and put the table in a List<> of ExpandoObjects. When I set DataGrid.ItemSource to the List the Grid remains visually empty. Explicitly defining columns and their data binding yields the runtime message that the application can't find the specified properties in the ExpandoObjects.

How can I display the table in the GridView? I work with Silverlight 5 RC and was hoping for a simple way to do it. At least simpler than the solutions I saw for Silverlight 2 and 3 so far.

Was it helpful?

Solution 2

I realized Vladimir Bodurov's solution works fine for me. I replaced the ExpandoObjects by Dictionaries and used Bodurov's class to transform the List into something the DataGrid can process.

OTHER TIPS

If it's dynamic and it doesn't implement ICustomTypeProvider, in Silverlight 5 it will not bind. It's really unfortunate since we have dynamic databinding in WPF, and in the case that properties can be known (like Expando), even writing a CustomType that would work for any IDynamicMetaObject provider isn't difficult, not to mention they could have just added it for Expando, especially since it's sealed.

So the bottom line is that you need to write your own dynamic type implementing ICustomTypeProvider

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top