EF5 Grdiview仅计数&只读 [英] EF5 Grdiview only Count & ReadOnly
问题描述
在Entity Framework中,当我添加从数据源拖动时,网格视图仅显示Count&是只读列,我也尝试过手动分配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我首先使用代码。
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.
Old:公共可重写属性PageElements作为List(Of PageElement )
新功能:作为ObservableCollection(Of PageElement)的公共可重写属性PageElements
删除现有数据源(和表单中的控件)。然后重新创建将数据源拖到窗体上。
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屋!