0

我想将 MyCustomers 绑定到 TreeListControl TreeListColumn FieldName="Id" Binding="How to bind CustomerId"我该怎么做?

<dxg:TreeListControl Name="MyControl" ItemsSource="{Binding Path=MyCustomers}" 
     Height="296" Width="750" Grid.Row="1" Grid.Column="0" HorizontalAlignment="Left">
    <dxg:TreeListControl.Columns>
        <dxg:TreeListColumn FieldName="Id"   Binding="How to Bind CustomerID ?????"    />
        <dxg:TreeListColumn FieldName="CustomerGroup" Binding="How to Bind CustomerGroup ?????" />
    </dxg:TreeListControl.Columns>
    <dxg:TreeListControl.View>
        <dxg:TreeListView AutoWidth="True" KeyFieldName="Id" ParentFieldName="ParentId" NavigationStyle="Row" />
    </dxg:TreeListControl.View>
</dxg:TreeListControl>

视图模型:

public class CustomerViewModel : BaseViewModel
{
    public IList<Model.App.Customer> MyCustomers
    {
        get;
        private set;
    }

    public CustomerViewModel()
    {
        CustomerDetail = new CustomerDetail();
        this.MyCustomers = CustomerRespiratory.SelectMyCustomers();
    }
}

模型:

public class Customer 
{
  public int CustomerID { get; set;}
  public int CustomerGroup { get; set;}
}
4

1 回答 1

1

您应该只将 CustomerID 指定为 Key Field,将 CustomerGroup 指定为 Parent Field。在“绑定到自引用数据结构”一文中非常清楚地描述了这一点:

<dxg:TreeListControl ItemsSource="{Binding Path=MyCustomers}">
    <dxg:TreeListControl.Columns>
        <dxg:TreeListColumn FieldName="CustomerId"/>
        <dxg:TreeListColumn FieldName="CustomerGroup"/>
    </dxg:TreeListControl.Columns>
    <dxg:TreeListControl.View>
        <dxg:TreeListView KeyFieldName="CustomerId" ParentFieldName="CustomerGroup" 
                AutoWidth="True" NavigationStyle="Row" />
    </dxg:TreeListControl.View>
</dxg:TreeListControl>

您可以在“TreeListView 数据绑定”文章中阅读更多内容。

另请参阅:
DXTreeList 入门 - 第 1 课 - 绑定到数据

于 2012-10-10T14:22:00.873 回答