This is a migrated thread and some comments may be shown as answers.

Dynamic Columns with DLR (S.Dynamic)

9 Answers 203 Views
GridView
This is a migrated thread and some comments may be shown as answers.
James Craig
Top achievements
Rank 1
James Craig asked on 22 Jun 2010, 12:35 PM
Dear All,

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;

Does anyone know if the DLR can used to, for instance, generate RadGridView columns dynamically?  Or is it a dead end in this respect?  If so, what is the current consensus regarding the optimal solution to this problem - one that allows normal grid features such as grouping, sorting, and editing?  Lightweight dataset?  Enumerable of Dictionary?  Is Dynamic LINQ useful or not?

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

Sort by
0
Accepted
Stefan Dobrev
Telerik team
answered on 25 Jun 2010, 10:25 AM
Hello James,

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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
James Craig
Top achievements
Rank 1
answered on 25 Jun 2010, 11:00 AM

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

0
Andre
Top achievements
Rank 1
answered on 21 Mar 2011, 03:22 PM
Hello,

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
0
Vlad
Telerik team
answered on 21 Mar 2011, 03:26 PM
Hello Andre,

 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.

All the best,
Vlad
the Telerik team
0
Andre
Top achievements
Rank 1
answered on 22 Mar 2011, 04:02 PM
Hi Vlad,

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é
0
Erik
Top achievements
Rank 2
answered on 16 Apr 2011, 01:30 PM
Hi all,

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
0
Vlad
Telerik team
answered on 18 Apr 2011, 06:27 AM
Hi,

 Here is it:
http://blogs.telerik.com/vladimirenchev/posts/09-04-23/lightweight_datatable_for_your_silverlight_applications.aspx

Best wishes,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Ken
Top achievements
Rank 1
answered on 10 Aug 2011, 03:16 PM
Hi Vlad,

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!
0
Vlad
Telerik team
answered on 10 Aug 2011, 03:22 PM
Hi Adrian,

 Here is the correct link:
http://blogs.telerik.com/vladimirenchev/posts/09-04-23/lightweight-datatable-for-your-silverlight-applications.aspx

Greetings,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

Tags
GridView
Asked by
James Craig
Top achievements
Rank 1
Answers by
Stefan Dobrev
Telerik team
James Craig
Top achievements
Rank 1
Andre
Top achievements
Rank 1
Vlad
Telerik team
Erik
Top achievements
Rank 2
Ken
Top achievements
Rank 1
Share this question
or