EF5 Grdiview 仅计数 &只读 [英] EF5 Grdiview only Count & ReadOnly

查看:23
本文介绍了EF5 Grdiview 仅计数 &只读的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在实体框架中,当我从数据源添加拖动时,网格视图仅显示计数 &是只读列,我也试过手动分配 datsource 但还是不行.

In Entity Framework When I add Drag from Datasource the grid view only shows Count & Is Read Only Column, I have also tried manually assigning datsource but still not working.

推荐答案

通过一些研究,我找到了解决方案.

Through some researh I have found a solution.

顺便说一句,我首先使用代码.

BTW I am using code first.

在父实体中,我将子属性从列表更改为 ObservableCollection.我还将命名空间 System.Collections.ObjectModel 添加到我的类中.

In the parent entity I changed the child property from list to ObservableCollection. I also added the namespace System.Collections.ObjectModel to my class.

旧:Public Overridable Property PageElements As List(Of PageElement)

新增:Public Overridable Property PageElements As ObservableCollection(Of PageElement)

删除您现有的数据源(以及表单中的控件).然后重新创建您的数据源并拖动到表单.

Delete your existing datasource (and controls from the form). Then recreate your datasource drag to the form.

您可能需要创建一个名为 ObservableListSource 的类并使用它来代替 ObservableCollection,但到目前为止它似乎已经解决了最初的问题.

You may need to create a class called ObservableListSource and use that instead of ObservableCollection, but it seems to have cleared up the original problem so far.

这是我在网上其他地方找到的 ObservableListSource 的建议定义.

Here a suggested definition for the ObservableListSource I found elsewhere on the web.

Public Class ObservableListSource(Of T As Class)
     Inherits ObservableCollection(Of T)
     Implements IListSource
     Private _bindingList As IBindingList

    Private ReadOnly Property ContainsListCollection() As Boolean Implements IListSource.ContainsListCollection
         Get
             Return False
         End Get
     End Property

    Private Function GetList() As IList Implements IListSource.GetList
         Return If(_bindingList, (InlineAssignHelper(_bindingList, Me.ToBindingList())))
     End Function
     Private Shared Function InlineAssignHelper(Of T)(ByRef target As T, value As T) As T
         target = value
         Return value
     End Function
EndCLass

这篇关于EF5 Grdiview 仅计数 &只读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆