Dynamic Columns with DLR (S.Dynamic)

10 posts, 1 answers
  1. James Craig
    James Craig avatar
    30 posts
    Member since:
    Mar 2010

    Posted 22 Jun 2010 Link to this post

    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
  2. Answer
    Stefan Dobrev
    Admin
    Stefan Dobrev avatar
    790 posts

    Posted 25 Jun 2010 Link to this post

    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
  3. DevCraft banner
  4. James Craig
    James Craig avatar
    30 posts
    Member since:
    Mar 2010

    Posted 25 Jun 2010 Link to this post

    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

  5. Andre
    Andre avatar
    31 posts
    Member since:
    Feb 2011

    Posted 21 Mar 2011 Link to this post

    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
  6. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 21 Mar 2011 Link to this post

    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
  7. Andre
    Andre avatar
    31 posts
    Member since:
    Feb 2011

    Posted 22 Mar 2011 Link to this post

    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é
  8. Erik
    Erik avatar
    314 posts
    Member since:
    Feb 2008

    Posted 16 Apr 2011 Link to this post

    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
  9. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 18 Apr 2011 Link to this post

    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
  10. Ken
    Ken avatar
    104 posts
    Member since:
    Aug 2010

    Posted 10 Aug 2011 Link to this post

    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!
  11. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 10 Aug 2011 Link to this post

    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 >>

Back to Top
DevCraft banner