Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm banging my head on my keyboard; it seems that the solution to this should be much easier to find, but after a days work I still don't have an answer. Unfortunately, I'm completely new to working with data, I'm usually just automating processes, and have only been working with WPF for 3 or 4 months.

With that said, the concept is simple (think MS Access). I want to create a DataGrid that is capable of displaying a table (Jobs). A related table (JobParts) should be able to be added as a "subDataSheet" which displays only parts related to the job selected in the outer DataGrid, from all of my research it looks like it will go in the RowDetailsTemplate. I have the XAMl below, but it does not produce the desired results.

What I end up with is only the outer DataGrid rows being populated. *1* The inner DataGrid remains unpopulated. *2* Also, I realize that, with the way my code is written now, even if the inner grid was populated it wouldn't show only the related rows for the selected outer grid row, but rather, it would show all of the rows in the inner table.


Code Behind:
C#
InitializeComponent();

PN10HistoryDataSet PN10History_ds = new PN10HistoryDataSet();

PN10HistoryDataSetTAbleAdapters.JobsTableAdapter Jobs_adapter = new PN10HistoryDataSetTAbleAdapters.JobsTAbleAdapter();

PN10HistoryDataSetTAbleAdapters.JobPartsTableAdapter JobParts_adapter = new PN10HistoryDataSetTAbleAdapters.JobPartsTAbleAdapter();

this.DataContext = PN10History_ds;

XAML:

HTML
<DataGrid
Name="objOuterDatagrid"
ItemsSource="{Binding Jobs}">
    <DataGrid.RowDetailsTemplate>
        <DataTemplate>
            <DataGrid
            Name="objInnerDatagrid"
            ItemsSource="{Binding JobParts}"></DataGrid>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
</DataGrid>
Thanks in advance!
Posted
Updated 24-Oct-14 6:55am
v3

1 solution

Original grid view is not well suited for hierarchical presentation of data; and the idea to nest controls like that is not very productive. However, some highly customized controls do such things better. You can find some in open source.

For example, you can consider this one: https://wpftoolkit.codeplex.com/wikipage?title=Advanced%20DataGrid[^].

This is the alternative based on list view: WPF TreeListView Control[^].

You can try to find something else. I would suggest this rather "sophisticated" query: http://bit.ly/1wmtIkG[^].

—SA
 
Share this answer
 
v4

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900