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

Convert Items to IEnumerable<> or List<>

1 Answer 401 Views
TreeListView
This is a migrated thread and some comments may be shown as answers.
StrandedPirate
Top achievements
Rank 1
StrandedPirate asked on 29 Jul 2010, 01:14 AM
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>'

1 Answer, 1 is accepted

Sort by
0
StrandedPirate
Top achievements
Rank 1
answered on 29 Jul 2010, 04:07 AM
Boom son.

 

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

 

Tags
TreeListView
Asked by
StrandedPirate
Top achievements
Rank 1
Answers by
StrandedPirate
Top achievements
Rank 1
Share this question
or