Infragistics xamDataGrid 绑定到分层数据 - 如何通知第二级网格发生更改?

发布于 2024-10-28 06:16:39 字数 870 浏览 6 评论 0原文

首先让我们想象一些域对象:

Customer:
  Name
  Phone
  List of Orders

Order:
  Date
  Amount

然后使用以下字段集设置我的网格:

<XamDataGrid>
  <XamDataGrid.FieldLayouts>
    <FieldLayout Key="Customers">
      <Field Name="Orders" IsExpandable="True" />
      <Field Name="Name" />
      <Field Name="Phone" />
    </FieldLayout>
    <FieldLayout ParentFieldLayoutKey="Customers">
      <Field Name="Date" />
      <Field Name="Amount" />
    </FieldLayout>
  </XamDataGrid.FieldLayouts>
</XamDataGrid>

当我的客户列表预先填充了数据时,这可以正常工作。每个客户行都有一个 +,单击时,该行会展开以显示订单列表。

现在,所有美好的事情都结束了......

我们尝试使订单异步,这在用户展开行时给我们一个空集合。当异步调用完成时,集合会更新,但网格不会更新。

由于集合最初是空的,因此网格删除了 +,并且用户不再具有折叠/展开的能力。如果当用户第一次展开行时集合包含数据,则当我们向集合添加更多对象时网格需要更新。

这应该如何运作?

Lets first imagine some domain objects:

Customer:
  Name
  Phone
  List of Orders

Order:
  Date
  Amount

My grid is then set up with the following field sets:

<XamDataGrid>
  <XamDataGrid.FieldLayouts>
    <FieldLayout Key="Customers">
      <Field Name="Orders" IsExpandable="True" />
      <Field Name="Name" />
      <Field Name="Phone" />
    </FieldLayout>
    <FieldLayout ParentFieldLayoutKey="Customers">
      <Field Name="Date" />
      <Field Name="Amount" />
    </FieldLayout>
  </XamDataGrid.FieldLayouts>
</XamDataGrid>

This works fine when my list of customers are pre-populated with data. Each customer row gets a +, and when clicked, the row expands to show the list of orders.

Now, all good things comes to an end...

We tried to get the orders async, which gives us an empty collection when the user expands the row. When the async call finish, the collection is updated, but the grid wont update.

Since the collection initially is empty, the grid removes the +, and the user no longer has the abillity to collaps/expand. If the collection contains data when the user first expands the row, the grid want update if we add more objects to the collection.

How is this supposed to work?

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

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

发布评论

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

评论(2

笑脸一如从前 2024-11-04 06:16:39

尝试使用 ObservableCollection 作为树结构中的节点集合。

Try to use ObservableCollection as collection of nodes in you tree-structure.

残龙傲雪 2024-11-04 06:16:39

请尝试这个..它有效

首先,

public class CustomerDetails1
    {
        public string Id { set; get; }
        public string Name { set; get; }
        public string Place { set; get; }
        public string Mobile { set; get; }
        public List<Level2Customer> Level2CustomerInst { get; set; }
    }

    public class Level2Customer
    {
        public string Address { set; get; }
        public string Street { set; get; }
    }

在Xaml页面中

<igWPF:XamDataGrid Width="767" Name ="TestDatagrid"  DataSource="{Binding CustomerList1}"   Height="403">
                                    <igWPF:XamDataGrid.FieldLayoutSettings>
                                        <igWPF:FieldLayoutSettings AutoGenerateFields="False"/>
                                    </igWPF:XamDataGrid.FieldLayoutSettings>
                                    <igWPF:XamDataGrid.ViewSettings>
                                        <igWPF:GridViewSettings UseNestedPanels="True" Orientation="Vertical"/>
                                    </igWPF:XamDataGrid.ViewSettings>
                                    <igWPF:XamDataGrid.FieldLayouts>
                                        <igWPF:FieldLayout Key="layer1">
                                            <igWPF:FieldLayout.Fields>
                                                <igWPF:Field Name="Id" Visibility="Visible"/>
                                                <igWPF:Field Name="Name" Visibility="Visible"/>
                                                <igWPF:Field Name="Place" Visibility="Visible"/>
                                                <igWPF:Field Name="Mobile" Visibility="Visible"/>
                                                <igWPF:Field Name="Level2CustomerInst" Visibility="Visible" IsExpandable="True" Label="Level2CustomerInst" IsSelected="True" IsPrimary="True" />
                                            </igWPF:FieldLayout.Fields>
                                        </igWPF:FieldLayout>
                                        <igWPF:FieldLayout Key="Level2CustomerInst"  ParentFieldName="Level2CustomerInst" ParentFieldLayoutKey="layer1">
                                            <igWPF:FieldLayout.Fields>
                                                <igWPF:Field Name="Address"  Label="Address"/>
                                                <igWPF:Field Name="Street"  Label="Street"/>                                                   
                                            </igWPF:FieldLayout.Fields>
                                        </igWPF:FieldLayout>
                                    </igWPF:XamDataGrid.FieldLayouts>

                                </igWPF:XamDataGrid>

创建两个这样的类如果您想在加载时展开子列表,您可以尝试处理InitializeRecord事件并设置Record的IsExpanded属性:

  private void TestDatagrid_OnInitializeRecord(object sender, InitializeRecordEventArgs e)
    {
       e.Record.IsExpanded = true;
    }

Please try this..It works

First of all,Create two classes like this

public class CustomerDetails1
    {
        public string Id { set; get; }
        public string Name { set; get; }
        public string Place { set; get; }
        public string Mobile { set; get; }
        public List<Level2Customer> Level2CustomerInst { get; set; }
    }

    public class Level2Customer
    {
        public string Address { set; get; }
        public string Street { set; get; }
    }

In Xaml page

<igWPF:XamDataGrid Width="767" Name ="TestDatagrid"  DataSource="{Binding CustomerList1}"   Height="403">
                                    <igWPF:XamDataGrid.FieldLayoutSettings>
                                        <igWPF:FieldLayoutSettings AutoGenerateFields="False"/>
                                    </igWPF:XamDataGrid.FieldLayoutSettings>
                                    <igWPF:XamDataGrid.ViewSettings>
                                        <igWPF:GridViewSettings UseNestedPanels="True" Orientation="Vertical"/>
                                    </igWPF:XamDataGrid.ViewSettings>
                                    <igWPF:XamDataGrid.FieldLayouts>
                                        <igWPF:FieldLayout Key="layer1">
                                            <igWPF:FieldLayout.Fields>
                                                <igWPF:Field Name="Id" Visibility="Visible"/>
                                                <igWPF:Field Name="Name" Visibility="Visible"/>
                                                <igWPF:Field Name="Place" Visibility="Visible"/>
                                                <igWPF:Field Name="Mobile" Visibility="Visible"/>
                                                <igWPF:Field Name="Level2CustomerInst" Visibility="Visible" IsExpandable="True" Label="Level2CustomerInst" IsSelected="True" IsPrimary="True" />
                                            </igWPF:FieldLayout.Fields>
                                        </igWPF:FieldLayout>
                                        <igWPF:FieldLayout Key="Level2CustomerInst"  ParentFieldName="Level2CustomerInst" ParentFieldLayoutKey="layer1">
                                            <igWPF:FieldLayout.Fields>
                                                <igWPF:Field Name="Address"  Label="Address"/>
                                                <igWPF:Field Name="Street"  Label="Street"/>                                                   
                                            </igWPF:FieldLayout.Fields>
                                        </igWPF:FieldLayout>
                                    </igWPF:XamDataGrid.FieldLayouts>

                                </igWPF:XamDataGrid>

If you want to expand the child list on load,You can try handling the InitializeRecord event and set the IsExpanded property of the Record:

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