SL4 |域数据源/数据网格 |添加空白行以插入新项目

发布于 2024-10-08 17:58:53 字数 1752 浏览 0 评论 0原文

我正在尝试将 DataForm 和 DataGrid 绑定到 DomainDataSource 并实现添加、删除和编辑项目的功能。

DataForm 部分的一切都运行良好。但是我如何使用 DataGrid 添加新记录呢? 据我所知,到目前为止,有两个工作选项:

  1. 向 DataView 添加一个新的“空白”项。

    • 问题:由于关键要求和限制,我遇到了验证错误。
  2. 使用 Silverlight 4 服务版本(2010 年 9 月)中的“SDK 功能在 DataGrid 控件中启用添加新行功能”

    • 问题:究竟发生了什么变化?没有新成员或文档。

以下是一些与我的项目最重要部分相匹配的基本标记声明:

<Grid x:Name="LayoutRoot">
    <sdk:DataGrid x:Name="ParentGrid" AutoGenerateColumns="False" ItemsSource="{Binding ElementName=parentDomainDataSource, Path=Data}"/>
    <toolkit:DataForm x:Name="ParentForm" CommandButtonsVisibility="All" Grid.Row="1" ItemsSource="{Binding ElementName=parentDomainDataSource, Path=Data}"/>

    <sdk:DataGrid x:Name="ChildGrid" Grid.Column="1" AutoGenerateColumns="False" ItemsSource="{Binding ElementName=childDomainDataSource, Path=Data}"/>
    <toolkit:DataForm x:Name="ChildForm" CommandButtonsVisibility="All" ItemsSource="{Binding ElementName=childDomainDataSource, Path=Data}"/>

    <riaControls:DomainDataSource AutoLoad="True" d:DesignData="{d:DesignInstance my1:Child, CreateList=true}" Name="childDomainDataSource" QueryName="GetChildrenQuery"
                                  DomainContext="{StaticResource domainCtx}"/>
    </riaControls:DomainDataSource>
    <riaControls:DomainDataSource AutoLoad="True" d:DesignData="{d:DesignInstance my1:Parent, CreateList=true}" Name="parentDomainDataSource" QueryName="GetParentsQuery" 
                                  DomainContext="{StaticResource domainCtx}"/>
</Grid>

不幸的是,我的时间不多了。

预先感谢您的任何帮助。来自德国的最诚挚的问候。希望任何人都可以提供帮助;)

I'm trying to bind a DataForm and DataGrid to a DomainDataSource and implement the functionality of adding, deleting and editing items.

Everything works very well for the DataForm part. But how I'm able to add a new record using the DataGrid?
Like I know until now, there are two working options:

  1. Add a new - "blank" - item to the DataView.

    • Problem: I'm getting validatoin errors as a result of key requirements and constraints.
  2. Using the "SDK feature to enable Add New Row capabilities in DataGrid control" from Silverlight 4 service release (September 2010)

    • Problem: What exactly has changed? There are no new members or a documentation.

Here are some basic markup declarations matching the most important parts of my project:

<Grid x:Name="LayoutRoot">
    <sdk:DataGrid x:Name="ParentGrid" AutoGenerateColumns="False" ItemsSource="{Binding ElementName=parentDomainDataSource, Path=Data}"/>
    <toolkit:DataForm x:Name="ParentForm" CommandButtonsVisibility="All" Grid.Row="1" ItemsSource="{Binding ElementName=parentDomainDataSource, Path=Data}"/>

    <sdk:DataGrid x:Name="ChildGrid" Grid.Column="1" AutoGenerateColumns="False" ItemsSource="{Binding ElementName=childDomainDataSource, Path=Data}"/>
    <toolkit:DataForm x:Name="ChildForm" CommandButtonsVisibility="All" ItemsSource="{Binding ElementName=childDomainDataSource, Path=Data}"/>

    <riaControls:DomainDataSource AutoLoad="True" d:DesignData="{d:DesignInstance my1:Child, CreateList=true}" Name="childDomainDataSource" QueryName="GetChildrenQuery"
                                  DomainContext="{StaticResource domainCtx}"/>
    </riaControls:DomainDataSource>
    <riaControls:DomainDataSource AutoLoad="True" d:DesignData="{d:DesignInstance my1:Parent, CreateList=true}" Name="parentDomainDataSource" QueryName="GetParentsQuery" 
                                  DomainContext="{StaticResource domainCtx}"/>
</Grid>

Unfortunately, I'm running out of time.

Thanks in advance for any help. Best regards from Germany. Hope anybody can help ;)

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

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

发布评论

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

评论(2

甜`诱少女 2024-10-15 17:58:53

我刚刚遇到这个问题试图找出类似的事情。在这里发帖是希望这可以节省其他人的时间:

在“新记录”Button's Click 的代码隐藏中:

private void OnNewRecordClick(object sender, System.Windows.RoutedEventArgs e)
{ childDomainDataSource.DataView.Add(new Child()); }

DataGrid 立即选取新记录并您仍然可以在 DDS 上执行 SubmitChangesCommand 将新条目发布回数据库。

I just ran into this question trying to figure out similar thing. Posting here in the hope that this saves somebody else the time:

In the code-behind for a "New Record" Button's Click:

private void OnNewRecordClick(object sender, System.Windows.RoutedEventArgs e)
{ childDomainDataSource.DataView.Add(new Child()); }

The DataGrid picks up the new record instantly and you can still do SubmitChangesCommand on DDS to post the new entry back to DB.

甜扑 2024-10-15 17:58:53

尽管它并没有严格回答您的问题,但使用 PagedCollectionView 效果相当好。此外,您可以按 Esc 键取消正在插入的行。

缺点是你必须做一些簿记工作。

private DomainService1 ctx = new DomainService1();
private PagedCollectionView pcvPersons = null;
private List<Person> tmpList = null;

private void LoadData()
{
    ctx.Load(ctx.GetPersonsQuery(),
        (op) =>
        {
            tmpList = new List<Person>(ctx.Persons);
            pcvPersons = new PagedCollectionView(tmpList);
            dataGrid1.ItemsSource = pcvPersons;
        }, null);
}

private void AddButton_Click(object sender, RoutedEventArgs e)
{
    Web.Person newItem = pcvPersons.AddNew();
}

Although it doesn't strictly answer your question, using a PagedCollectionView works rather nicely. In addition, you can hit Esc to cancel the row being inserted.

The downside is you have to do a little bit of book-keeping.

private DomainService1 ctx = new DomainService1();
private PagedCollectionView pcvPersons = null;
private List<Person> tmpList = null;

private void LoadData()
{
    ctx.Load(ctx.GetPersonsQuery(),
        (op) =>
        {
            tmpList = new List<Person>(ctx.Persons);
            pcvPersons = new PagedCollectionView(tmpList);
            dataGrid1.ItemsSource = pcvPersons;
        }, null);
}

private void AddButton_Click(object sender, RoutedEventArgs e)
{
    Web.Person newItem = pcvPersons.AddNew();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文