Silverlight 4 将新项目添加到 DomainDataSource

发布于 11-17 23:47 字数 612 浏览 12 评论 0原文

我有一个简单的数据网格,列出地址和一个子窗口,用户可以在其中编辑/添加新地址。在带有数据网格的主窗体上,我有一个“插入新地址”按钮,该按钮应该使用空的地址对象加载子窗口。但是它不会让我添加记录。我做错了什么吗?我当前的代码如下:

    Dim address As New Address
    Dim frmAddressObj As New frmAddress

    If frmAddressObj.AddressDomainDataSource.DataView.CanAdd = False Then
        frmAddressObj.AddressDomainDataSource.Load()
    End If
    frmAddressObj.AddressDomainDataSource.DataView.Add(address)

Address 是地址对象。 frmAddress 是子窗口窗体。 AddressDomainDataSource 与我在数据网格中使用的数据源与在子级中使用的数据源相同。 CanAdd 总是错误的,我被告知在添加之前尝试加载,但这似乎没有帮助。当它到达 Add 方法时,它返回此 ICollectionView 不支持“Add”的异常。任何帮助将不胜感激。谢谢

I have a simple datagrid listing addresses and a child window where the user can edit/add new. On the main form with the datagrid i have a button to "Insert New Address" which should load the child window with an empty Address object. However it will not let me add a record. Am i doing something wrong? my current code is as follows:

    Dim address As New Address
    Dim frmAddressObj As New frmAddress

    If frmAddressObj.AddressDomainDataSource.DataView.CanAdd = False Then
        frmAddressObj.AddressDomainDataSource.Load()
    End If
    frmAddressObj.AddressDomainDataSource.DataView.Add(address)

Address is the address object. frmAddress is the child window form. AddressDomainDataSource is the same datasource i use in the datagrid as i use in the child. CanAdd is always false and i got told to try loading before adding but this does not appear to have helped. When it reaches the Add method it returns an Exception of 'Add' is not supported by this ICollectionView. Any help would be appreciated. Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

寂寞清仓2024-11-24 23:47:02

DataView 字段应被视为只读集合。 DomainDataSource 与 DataGrid 的最简单的一般用法如下:

(myDataSource.DomainContext as myDomainContext).my_entitys.Remove(dgOrders.SelectedItem as order);
(myDataSource.DomainContext as myDomainContext).SubmitChanges();

它与插入类似,您只需使用

my_entitys.Add(myNewEntityInstance); 

而不是

my_entitys.Remove(entityToRemove);

,而对于更新您只需调用

(myDataSource.DomainContext as myDomainContext).SubmitChanges();

The DataView field should be thought of as a read-only collection. The simplest general usage of the DomainDataSource with a DataGrid goes something like this:

(myDataSource.DomainContext as myDomainContext).my_entitys.Remove(dgOrders.SelectedItem as order);
(myDataSource.DomainContext as myDomainContext).SubmitChanges();

It is similar for insert, you just use

my_entitys.Add(myNewEntityInstance); 

instead of

my_entitys.Remove(entityToRemove);

And for updates you simply call

(myDataSource.DomainContext as myDomainContext).SubmitChanges();
快乐很简单2024-11-24 23:47:02

您的域服务中还必须具有插入方法。因此,请确保您有一个类似于以下内容的方法:

Public Sub InsertAddress(address As Address)
End Sub

或 C#

public void InsertAddress(Address address)

You must also have the insert method in your domain service. So make sure you have a method that looks like:

Public Sub InsertAddress(address As Address)
End Sub

or in C#

public void InsertAddress(Address address)
笑咖2024-11-24 23:47:02

我最近遇到了同样的问题,就我而言,DomainDataSource 尚未加载(甚至尚未绑定到其上下文),因为它驻留在未选择的 TabItem 中。

确保您的 DomainDataSource 已正确加载到可视化树中,这解决了我的问题。

I had the same problem recently and in my case, the DomainDataSource wasn't loaded (or even bound to its context yet) because it resided in a TabItem that wasn't selected.

Make sure you have your DomainDataSource properly loaded in the visual tree, that solved the issue in my case.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文