【问题标题】:DataGrid ItemSource bound to selected item within another DataGridDataGrid ItemSsource 绑定到另一个 DataGrid 中的选定项
【发布时间】:2011-10-21 09:14:10
【问题描述】:

我有以下数据结构:

List<Customer> currentCustomers {...}

public class Customer 
{
    public string ID { get, set }
    public string Name { get, set } 
    [...]
    public List<Products> { get, set } 
}

我有一个绑定到currentCustomers 列表的客户DataGrid。 我希望能够将第二个 DataGrid 绑定到客户中的选定项目,以显示该客户的所有产品信息。

即用户单击客户数据网格中的客户,然后根据该客户产品自动更新第二个数据网格。

这可能吗?

如果是这样,是否有资源可以告诉/告诉我这是如何完成的?

【问题讨论】:

    标签: c# wpf data-binding datagrid


    【解决方案1】:

    这应该可行:

    <DataGrid x:Name="one"></DataGrid>
    <DataGrid x:Name="two" DataContext="{Binding ElementName=one, Path=SelectedItem.Products}"></DataGrid>
    

    【讨论】:

      【解决方案2】:

      只需将其绑定到SelectedItem 属性:

      <DataGrid x:Name="customersList" CanSelectMultipleItems="false" ... />
      
      <DataGrid x:Name="customerDetails" 
                ItemsSource = "{Binding ElementName = customersList, 
                                        Path = SelectedItem.Products}">
      

      【讨论】:

        猜你喜欢
        • 2013-01-14
        • 2017-05-11
        • 2013-10-07
        • 2017-09-18
        • 2011-12-17
        • 1970-01-01
        • 2023-03-07
        • 1970-01-01
        • 2015-11-22
        相关资源
        最近更新 更多