2

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?

Vegar
  • 12,828
  • 16
  • 85
  • 151

2 Answers2

3

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

Marek Kwiendacz
  • 9,524
  • 14
  • 48
  • 72
  • Wow. That easy? The only problem now, is that the changes happens in a background thread, so we need to find a way of making the observable collection signal changed on the ui thread. Thanks! – Vegar Mar 30 '11 at 21:16
0

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;
    }
Deepak Kv
  • 61
  • 9