Convert Items to IEnumerable<> or List<>

2 posts, 0 answers
  1. StrandedPirate
    StrandedPirate avatar
    32 posts
    Member since:
    Nov 2007

    Posted 28 Jul 2010 Link to this post

    Hi, got myself a TreeListView on my page with the ItemSource bound to a collection of poco objects. How do I convert the tree view's Items property back into the collection of strongly typed objects? I want to get the collection back strongly typed so I can use linq to query it as shown here:

     

     

    IEnumerable<UserPermission> permissionList = (IEnumerable<UserPermission>)OperationList.Items;

     

     

     

    UserPermission permission = permissionList.Where(a => a.Permission == Enum.Parse(a.Permission.GetType(), acl.Permission.ToString(), true)).FirstOrDefault();

    This currently explodes with:

     

    Cannot cast '((Telerik.Windows.Controls.DataControl)(this.OperationList)).Items' (which has an actual type of 'Telerik.Windows.Data.DataItemCollection') to 'System.Collections.Generic.IEnumerable<MyNamespace.UserPermission>'

  2. StrandedPirate
    StrandedPirate avatar
    32 posts
    Member since:
    Nov 2007

    Posted 28 Jul 2010 Link to this post

    Boom son.

     

    IEnumerable<UserPermission> permissionList = OperationList.Items.Cast<UserPermission>();

     

  3. DevCraft banner
Back to Top