Click here to Skip to main content
12,404,478 members (70,964 online)
Rate this:
Please Sign up or sign in to vote.
Hi all,

I've got a custom collection AllItems. Each item within this has string Make, string Model and List StockItems.

I have a datagrid bound to this custom collection showing the Make, Model and StockItems.Count. This works fine, but when the user clicks on one of the rows I have another datagrid to show the expanded details withing StockItems.

So effectively my 2nd datagrid needs to be bound to StockItems and also the Make and Model. I can bind two columns to StockItems, but I then wish to have the further details shown next to that data as follows:

datagrid 1 - ItemsSource is set to AllItems

<DataGrid x:Name="datagridStockMovements" AlternatingRowremoved="#FFE2E2E2" IsReadOnly="True" AlternationCount="2" AutoGenerateColumns="False" MouseDown="datagridStockMovements_MouseDown" Visibility="Hidden">
                                                    <DataGridTextColumn Header="Manufacturer" MinWidth="200" Binding="{Binding Path=Manufacturer}" />
                                                    <DataGridTextColumn Header="Model" MinWidth="200" Binding="{Binding Path=ModelName}" />
                                                    <DataGridTemplateColumn Header="Quantity" MinWidth="200">
                                                                    <TextBlock Text="{Binding Path=ListOfDevices.Count}" />
                                                    </DataGridTemplateColumn >

datagrid2 - ItemsSource is set to StockItems and also needs to include AllItems.Model & AllItems.Manufacturer

<DataGrid x:Name="datagridStockMovementDetails" Grid.Row="1" IsReadOnly="True" AlternatingRowremoved="#FFE2E2E2" AlternationCount="2" AutoGenerateColumns="False" Visibility="Hidden">
                                        <DataGridTextColumn Header="Serial" MinWidth="200" Binding="{Binding Path=Serial}" />
                                        <DataGridTextColumn Header="Machine Name" MinWidth="200" Binding="{Binding Path=MachineName}" />
                                        <DataGridTextColumn Header="Model" MinWidth="200" Binding="{Binding Path=Parent.Model}" />
                                        <DataGridTextColumn Header="Make" MinWidth="200" Binding="{Binding Path=Parent.Manufacturer}" />

I'm struggling to explain this well I feel, but it seems that in the expanded datagrid I'm binding to the list within my custom object, then I also want to take the details of Make and Model into that binding with XAML.

Anyone know how to do this?


Posted 23-Jan-12 0:17am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Ok, this is quite crude, but it gets you what you want:

                DataContext="{Binding ElementName=datagridStockMovements, Path=SelectedValue}">
Jibrohni 24-Jan-12 4:55am
That's great - it's working just as I'd hoped although it seems to replace the original datagrid with the second, rather than display both concurrently. Any ideas? They should display in different row of my grid but it doesn't seem to be working that way.
Jibrohni 24-Jan-12 5:13am
Ignore that! Thank you very much for your help, that's great!
SteveAdey 24-Jan-12 6:02am
No problem, glad to help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.160721.1 | Last Updated 23 Jan 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100