Reputation: 47873
I have the following Data Structures:
List<Customer> currentCustomers {...}
public class Customer
{
public string ID { get, set }
public string Name { get, set }
[...]
public List<Products> { get, set }
}
I have a customers DataGrid bound to the currentCustomers
List.
What I would like to be able to do is bind a second DataGrid to the selected item within customers to display all the Product information for that Customer.
i.e. The user clicks on a Customer within the Customers DataGrid, this then automatically updates a second DataGrid based on that Customers Products.
Is this even possible?
If so, is there a resource around that will tell/show me how this is done?
Upvotes: 0
Views: 611
Reputation: 62494
Just bind it to SelectedItem property:
<DataGrid x:Name="customersList" CanSelectMultipleItems="false" ... />
<DataGrid x:Name="customerDetails"
ItemsSource = "{Binding ElementName = customersList,
Path = SelectedItem.Products}">
Upvotes: 2
Reputation: 12458
This should work:
<DataGrid x:Name="one"></DataGrid>
<DataGrid x:Name="two" DataContext="{Binding ElementName=one, Path=SelectedItem.Products}"></DataGrid>
Upvotes: 3