datagrid: complex rowdetails

Nov 6, 2008 at 10:22 AM
Hi

I want to achieve the following:

I have a list of countries in my datagrid.
As rowdetails for each country, I want to display a list of cities of the country. I want to display the cities in a datagrid too.
In the cities grid, I want to have another rowdetails which should show the streets in the single city, also using a datagrid.

So this comes to a nested master-detail-grid with 3 levels: country-city-street

1) Is this possible? I would think yes
2) How can I read the rowdetails data only in the moment when it must be read (when the rowdetails are shown)?
3) Is there an example of how to do this in code?

Thanks for your support
Klaus
Coordinator
Nov 10, 2008 at 6:29 PM
Here is an example using data from one of Beatriz's posts.  


         <XmlDataProvider x:Key="XmlDataProvider2" XPath="Mountains/Mountain">
                <x:XData>
                    <Mountains xmlns="">
                        <Mountain Name="Whistler">
                            <Lifts>
                                <Lift Name="Big Red Express">
                                    <Runs>
                                        <Run>Headwall</Run>
                                        <Run>Fisheye</Run>
                                        <Run>Jimmy's Joker</Run>
                                    </Runs>
                                </Lift>
                                <Lift Name="Garbanzo Express">
                                    <Runs>
                                        <Run>Raven</Run>
                                    </Runs>
                                </Lift>
                                <Lift Name="Orange chair">
                                    <Runs>
                                        <Run>Orange peel</Run>
                                        <Run>Banana peel</Run>
                                        <Run>Upper Dave Murray Downhill</Run>
                                    </Runs>
                                </Lift>
                            </Lifts>
                        </Mountain>
                        <Mountain Name="Stevens Pass">
                            <Lifts>
                                <Lift Name="Tye Mill">
                                    <Runs>
                                        <Run>Roller coaster</Run>
                                        <Run>Skid road</Run>
                                        <Run>Crest trail</Run>
                                    </Runs>
                                </Lift>
                                <Lift Name="Jupiter chair">
                                    <Runs>
                                        <Run>Corona bowl</Run>
                                        <Run>Lower gemini</Run>
                                    </Runs>
                                </Lift>
                                <Lift Name="Southern cross chair">
                                    <Runs>
                                        <Run>Orion</Run>
                                        <Run>Aquarius face</Run>
                                    </Runs>
                                </Lift>
                            </Lifts>
                        </Mountain>
                        <Mountain Name="Crystal Mountain">
                            <Lifts>
                                <Lift Name="Rainier Express">
                                    <Runs>
                                        <Run>Iceberg ridge</Run>
                                        <Run>Pro course</Run>
                                        <Run>Lucky shot</Run>
                                    </Runs>
                                </Lift>
                                <Lift Name="Green Valley">
                                    <Runs>
                                        <Run>Green back</Run>
                                        <Run>Northway ridge</Run>
                                    </Runs>
                                </Lift>
                            </Lifts>
                        </Mountain>
                    </Mountains>
                </x:XData>
            </XmlDataProvider>


         <dg:DataGrid Name="dataGrid"
                     Grid.Row="1"
                     ItemsSource="{Binding Source={StaticResource XmlDataProvider2}}"
                     HeadersVisibility="Column"                    
                     GridLinesVisibility="Horizontal"
                     RowBackground="LightGray"
                     IsReadOnly="True"
                     AutoGenerateColumns="False">
            <dg:DataGrid.RowDetailsTemplate>
                <DataTemplate>
                    <Grid Margin="20,0,0,0">
                        <dg:DataGrid ItemsSource="{Binding XPath=Lifts/Lift}"
                                     Name="dataGrid2"
                                     HeadersVisibility="Column"
                                     GridLinesVisibility="Horizontal"
                                     RowBackground="Gray"
                                     IsReadOnly="True"
                                     AutoGenerateColumns="False">
                            <dg:DataGrid.RowDetailsTemplate>
                                <DataTemplate>
                                    <Grid Margin="20,0,0,0">
                                        <dg:DataGrid ItemsSource="{Binding XPath=Runs/Run}"
                                                     Name="dataGrid3"
                                                     HeadersVisibility="Column"
                                                     GridLinesVisibility="Horizontal"
                                                     RowBackground="LightGray"
                                                     IsReadOnly="True"
                                                     AutoGenerateColumns="False">
                                            <dg:DataGrid.Columns>
                                                <dg:DataGridTextColumn Header="Run" Binding="{Binding XPath=.}" Width="Auto" />
                                            </dg:DataGrid.Columns>
                                        </dg:DataGrid>
                                    </Grid>
                                </DataTemplate>
                            </dg:DataGrid.RowDetailsTemplate>
                            <dg:DataGrid.Columns>
                                <dg:DataGridTextColumn Header="Lift" Binding="{Binding XPath=@Name}" Width="Auto" />
                            </dg:DataGrid.Columns>
                        </dg:DataGrid>
                    </Grid>
                </DataTemplate>
            </dg:DataGrid.RowDetailsTemplate>
            <dg:DataGrid.Columns>
                <dg:DataGridTextColumn Header="Mountain" Binding="{Binding XPath=@Name}" Width="Auto" />
            </dg:DataGrid.Columns>
        </dg:DataGrid>



Nov 11, 2008 at 9:37 AM
Hi

just to clarify: when using rowdetails like above, when will the data for the rowdetails be "read"?

If I have an "expensive" retrieval of the rowdetails, I might not want to read all details in advance, but only if the user really chooses a new row.

So the question is: are rowdetails data read asynchronously by default ?

Regards
Klaus
Coordinator
Nov 11, 2008 at 5:25 PM
Data is not read asynchronously.  Josh Smith has a great example for loading data in a treeview on demand.  The article lives here, http://www.codeproject.com/KB/WPF/TreeViewWithViewModel.aspx.
Mar 28, 2009 at 2:08 AM
Vincent-

The above example makes sense when I see it related to XPath binding. In my scenario using LINQ to Entitites, the ItemSource property is directly bound to a table-mapped entitity. For example: Customers, and CustomersOrders. I would like to have the row details in the first expand to have a data grid displaying the orders particular for that customer.

One thing I noticed is that I cannot seem to set the ItemSource property of the nested data grid in C# (im assuming because it is part of the template area and doesnt register on the C# side), but I cannot seem to find out how in XAML I would say "fetch the Orders table, where the CustomerID = x"

Any ideas?
Apr 7, 2009 at 9:51 PM
Any further information?
Oct 5, 2009 at 10:57 AM

Hi all!

I have exact the same scenario as described from vinsibal. A DataGrid with a DataGrid as Rowdetails and so on. so I get a n-level hierarchy. I set the SelectionMode of all DataGrids  to single.

Now my problem: If I select a row from the second level and then select an other row from the same table,  the used space from the selected row before is still diplayed. So there is a empty space between the first and second level.

What is the problem?

Regrads

Hendrik