I need to bind RadGridView to a datasource whose fields cannot be known until runtime. Obviously, this requirement precludes the use of entity classes. A quick search of these forums brings up several possible solutions, all based on the Silverlight 3 Framework. I had hoped, however, that Silverlight 4's support for System.Dynamic might have allowed for a cleaner and more complete solution to this long-running issue. But so far I haven't found examples of the DLR being used in this way (at present, it seems to offer nothing more than a convenient way to access hashtables). Certainly, RadGridView can't detect properties added to an ExpandoObject like so:
dynamic
d1 = new ExpandoObject();
d1.Id =
Guid.NewGuid();
d1.Name =
"Name";
d1.PensionScheme =
false;
d1.Dob =
DateTime.Now.AddYears(-25);
List
<dynamic> lstDynamic = new List<dynamic>() { d1 };
radGridView1.ItemsSource = lstDynamic;
Any advice that summarises the current state of play as of Silverlight 4 would be massively appreciated.
Many thanks in advance,
James
9 Answers, 1 is accepted
Currently RadGridView do not support binding to dynamic objects, but we have this feature in our product backlog. You can even vote for it in PITS here.
Regarding the display of objects of dynamic shape my suggestion for you is to either use Silverlight's DataTable or MicroModels for Silverlight.
Sincerely yours,
Stefan Dobrev
the Telerik team
Hello Stefan,
Many thanks for your reply. When I started this thread, it was with the aim finding a way to avoid totally the process of defining assemblies and types at runtime. However, I've since come around to the idea as 1) without type descriptors, it appears to be the best option; and 2) the blog posts by yourself and other Telerik staff have proved immensely helpful, and instrumental in convincing me that the process isn't so evil after all! Keep up the good work!
Best regards,
James
I tried DataTable for dynamically adding columns and I'm having one issue: when the column header has hyphen, no data is shown for that column.
Any thoughts?
Thanks in advance,
André Carlucci
I've already replied to your comment on my blog post.
Unfortunately you cannot have properties with white space in the property name. The table will attempt to create dynamic class with such property name. You can use the grid AutoGeneratingColumn event for example to change the column Header property to desired or declare columns manually.
Vlad
the Telerik team
Thanks for the quick answer.
I took a look at how DataTable works and you're right, no way to do it this way.
To solve my problem, I extended RadGridView and added a dependency property where I can bind the column definitions from my viewmodel. It worked :)
Thanks again for the tip.
Cheers,
André
Is there a way now to bind dynamic objects to a radgrid. I see blog's motioned, but can't seem to find it...
Regards,
Erik
Vlad
the Telerik team
The download link on your blog post is broken. Can you fix it please? Or maybe there is another solution in the meantime (since the one on your blog is from 2 years ago)?...
Thanks!
Here is the correct link:
http://blogs.telerik.com/vladimirenchev/posts/09-04-23/lightweight-datatable-for-your-silverlight-applications.aspx
Vlad
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>