Click here to Skip to main content
Rate this: bad
good
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">
                                                <DataGrid.Columns>
                                                    <DataGridTextColumn Header="Manufacturer" MinWidth="200" Binding="{Binding Path=Manufacturer}" />
                                                    <DataGridTextColumn Header="Model" MinWidth="200" Binding="{Binding Path=ModelName}" />
                                                    <DataGridTemplateColumn Header="Quantity" MinWidth="200">
                                                        <DataGridTemplateColumn.CellTemplate>
                                                            <DataTemplate>
                                                                <DockPanel>
                                                                    <TextBlock Text="{Binding Path=ListOfDevices.Count}" />
                                                                </DockPanel>
                                                            </DataTemplate>
                                                        </DataGridTemplateColumn.CellTemplate>
                                                    </DataGridTemplateColumn >
                                                </DataGrid.Columns>
                                            </DataGrid>
 
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">
                                    <DataGrid.Columns>
                                        <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}" />
                                    </DataGrid.Columns>
                                </DataGrid>
 
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?
 
Regards,
 
Jib
Posted 23-Jan-12 1:17am
Jibrohni1.1K

1 solution

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

Solution 1

Ok, this is quite crude, but it gets you what you want:
 
            <contentcontrol>
                Name="stockItems"
                DataContext="{Binding ElementName=datagridStockMovements, Path=SelectedValue}">
  Permalink  
Comments
Jibrohni at 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 at 24-Jan-12 5:13am
   
Ignore that! Thank you very much for your help, that's great!
SteveAdey at 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
0 OriginalGriff 330
1 Sergey Alexandrovich Kryukov 279
2 BillWoodruff 245
3 Afzaal Ahmad Zeeshan 215
4 CPallini 205
0 OriginalGriff 5,635
1 DamithSL 4,496
2 Maciej Los 3,942
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 23 Jan 2012
Copyright © CodeProject, 1999-2014
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