datagrid绑定问题,快来看呐绑定代码C# code var query from i in lo.Entitiesselect new {i.CPU利用率,i
datagrid绑定问题,快来看呐
绑定代码
C# code var query = from i in lo.Entities select new {i.CPU利用率,i.内存利用率,i.上行速率,i.下行速率}; this.PMGrid.ItemsSource = query.ToList();
这样是报错的,错误信息如下
可行的是
C# codethis.PMGrid.ItemsSource = lo.Entities;[/
但是我现在只需要取到4个字段就可以了,而且,不能在xaml中写死
ps:错误信息
{System.MethodAccessException: 方法“System.Linq.EnumerableQuery.Create(System.Type, System.Collections.IEnumerable)”访问方法“System.Linq.EnumerableQuery`1<System.__Canon>..ctor(System.Collections.Generic.IEnumerable`1<System.__Canon>)”的尝试失败。
位于 System.RuntimeMethodHandle.PerformSecurityCheck(Object obj, RuntimeMethodHandleInternal method, RuntimeType parent, UInt32 invocationFlags)
位于 System.RuntimeMethodHandle.PerformSecurityCheck(Object obj, IRuntimeMethodInfo method, RuntimeType parent, UInt32 invocationFlags)
位于 System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
位于 System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
位于 System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
位于 System.Activator.CreateInstance(Type type, Object[] args)
位于 System.Linq.EnumerableQuery.Create(Type elementType, IEnumerable sequence)
位于 System.Linq.Queryable.AsQueryable(IEnumerable source)
位于 Telerik.Windows.Data.QueryableFactory.CreateQueryable(IEnumerable source)
位于 Telerik.Windows.Data.QueryableCollectionView.InitializeQueryableSourceCollection()
位于 Telerik.Windows.Data.QueryableCollectionView..ctor(IEnumerable sourceCollection)
位于 Telerik.Windows.Data.DataItemCollection.CreateCollectionView(IEnumerable source)
位于 Telerik.Windows.Data.DataItemCollection.SetItemsSource(IEnumerable source)
位于 Telerik.Windows.Controls.GridView.GridViewDataControl.<>c__DisplayClass18.<Bind>b__17()
位于 Telerik.Windows.Controls.CursorManager.PerformTimeConsumingOperation(FrameworkElement frameworkElement, Action action)
位于 Telerik.Windows.Controls.GridView.GridViewDataControl.Bind(Object newValue)
位于 Telerik.Windows.Controls.GridView.GridViewDataControl.OnItemsSourceChanged(Object oldValue, Object newValue)
位于 Telerik.Windows.Controls.DataControl.OnItemsSourcePropertyChanged(DependencyObject origin, DependencyPropertyChangedEventArgs args)
位于 Telerik.Windows.PropertyMetadata.<>c__DisplayClass1.<Create>b__0(DependencyObject d, DependencyPropertyChangedEventArgs e)
位于 System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object oldValue, Object newValue)
位于 System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)
位于 System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet)
位于 System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
位于 Telerik.Windows.Controls.DataControl.set_ItemsSource(Object value)
位于 ECNTMap.Views.NetOptimization.PMInfo.<btn_Search_Click>b__0(LoadOperation`1 lo)
位于 System.ServiceModel.DomainServices.Client.DomainContext.<>c__DisplayClass13`1.<Load>b__11(LoadOperation lo)
位于 System.ServiceModel.DomainServices.Client.LoadOperation.<>c__DisplayClass4`1.<Create>b__0(LoadOperation`1 arg)
位于 System.ServiceModel.DomainServices.Client.LoadOperation`1.InvokeCompleteAction()
位于 System.ServiceModel.DomainServices.Client.OperationBase.Complete(Object result)
位于 System.ServiceModel.DomainServices.Client.LoadOperation.Complete(DomainClientResult result)
位于 System.ServiceModel.DomainServices.Client.DomainContext.CompleteLoad(IAsyncResult asyncResult)
位于 System.ServiceModel.DomainServices.Client.DomainContext.<>c__DisplayClass1b.<Load>b__17(Object )}
[解决办法]
C# codevar query = from i in lo.Entities selectnew { CPU利用率=i.CPU利用率, 内存利用率 =i.内存利用率, 上行速率=i.上行速率, 下行速率= i.下行速率}; this.PMGrid.ItemsSource = query.ToList();