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

Using a Linq statement in the ItemSource

2 Answers 192 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 02 Jul 2010, 09:44 PM
My apologies in advance on this one.  I'm a noob to .Net 4, to Linq, to Silverlight, and to Telerik.  Most likely this isn't even a Telerik question and is only something I'm not understanding.  Can anyone point me in the right direction?

In the following lines, rgvCust is a GridView, and custResult is a list of objects.  This code works just fine.
rgvCust.ItemsSource = null;
rgvCust.AutoGenerateColumns = true;
rgvCust.Columns.Clear();
rgvCust.ItemsSource = custResult;

In the following lines, I'm attempting to use Linq on the objects themselves.  This fails with the error message pasted below.
rgvCust.ItemsSource = null;
rgvCust.AutoGenerateColumns = true;
rgvCust.Columns.Clear();
rgvCust.ItemsSource = from x in custResult
           orderby x.LastName
                      select new
                      {
                          x.FirstName,
                            x.LastName,
                           x.Address,
                            x.City,
                            x.State
                          };

{System.MethodAccessException: Attempt by method 'System.Linq.EnumerableQuery.Create(System.Type, System.Collections.IEnumerable)' to access method 'System.Linq.EnumerableQuery`1<System.__Canon>..ctor(System.Collections.Generic.IEnumerable`1<System.__Canon>)' failed.
   at System.RuntimeMethodHandle.PerformSecurityCheck(Object obj, RuntimeMethodHandleInternal method, RuntimeType parent, UInt32 invocationFlags)
   at System.RuntimeMethodHandle.PerformSecurityCheck(Object obj, IRuntimeMethodInfo method, RuntimeType parent, UInt32 invocationFlags)
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
   at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
   at System.Activator.CreateInstance(Type type, Object[] args)
   at System.Linq.EnumerableQuery.Create(Type elementType, IEnumerable sequence)
   at System.Linq.Queryable.AsQueryable(IEnumerable source)
   at Telerik.Windows.Data.QueryableFactory.CreateQueryable(IEnumerable source)
   at Telerik.Windows.Data.QueryableCollectionView.InitializeQueryableSourceCollection()
   at Telerik.Windows.Data.QueryableCollectionView..ctor(IEnumerable sourceCollection)
   at Telerik.Windows.Data.DataItemCollection.CreateCollectionView(IEnumerable source)
   at Telerik.Windows.Data.DataItemCollection.SetItemsSource(IEnumerable source)
   at Telerik.Windows.Controls.GridView.GridViewDataControl.<>c__DisplayClass49.<Bind>b__48()
   at Telerik.Windows.Controls.CursorManager.PerformTimeConsumingOperation(FrameworkElement frameworkElement, Action action)
   at Telerik.Windows.Controls.GridView.GridViewDataControl.Bind(Object newValue)
   at Telerik.Windows.Controls.GridView.GridViewDataControl.OnItemsSourceChanged(Object oldValue, Object newValue)
   at Telerik.Windows.Controls.DataControl.OnItemsSourcePropertyChanged(DependencyObject origin, DependencyPropertyChangedEventArgs args)
   at Telerik.Windows.PropertyMetadata.<>c__DisplayClass1.<Create>b__0(DependencyObject d, DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object oldValue, Object newValue)
   at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)
   at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet)
   at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
   at Telerik.Windows.Controls.DataControl.set_ItemsSource(Object value)
   at RadControlsSilverlightApp1.MainPage.btnToggle_Click(Object sender, RoutedEventArgs e)
   at System.Windows.Controls.Primitives.ButtonBase.OnClick()
   at System.Windows.Controls.Button.OnClick()
   at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
   at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)
   at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)}

Any idea is appreciated!  Paul

2 Answers, 1 is accepted

Sort by
0
Paul
Top achievements
Rank 1
answered on 02 Jul 2010, 09:46 PM
I should have added - this does work for a RadComboBox.
0
Accepted
Vlad
Telerik team
answered on 05 Jul 2010, 07:40 AM
Hi Paul,

 Binding RadGridView to list of anonymous types in Silverlight is not supported! Anonymous types in Silverlight are internal and the grid cannot resolve type properties.

Greetings,
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
Tags
GridView
Asked by
Paul
Top achievements
Rank 1
Answers by
Paul
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or