如何使用1个DataSet,2个相关DataTable,1个DataGrid创建分层DataGrid? [英] How do I Create a Hierarchical DataGrid using 1 DataSet, 2 Related DataTables, 1 DataGrid?

查看:65
本文介绍了如何使用1个DataSet,2个相关DataTable,1个DataGrid创建分层DataGrid?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在敲我的键盘;似乎解决方案应该更容易找到,但经过一天的工作后,我仍然没有答案。不幸的是,我对使用数据完全不熟悉,我通常只是自动化流程,并且只使用WPF 3到4个月。



随着那说,概念很简单(想想MS Access)。我想创建一个能够显示表(作业)的DataGrid。一个相关的表(JobParts)应该能够添加为subDataSheet,它只显示与在外部DataGrid中选择的作业相关的部分,从我的所有研究看起来它将在RowDetailsTemplate中。我有下面的XAMl,但它不会产生预期的结果。



我最终得到的只是填充的外部DataGrid行。 * 1 *内部DataGrid仍未填充。 * 2 *此外,我意识到,通过我现在编写代码的方式,即使内部网格已填充,它也不会仅显示所选外部网格行的相关行,而是显示所有的内表中的行。





Code Behind:

的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:



 <   DataGrid   

名称 = objOuterDatagrid

ItemsSource = {Binding Jobs} >
< DataGrid.RowDetailsTemplate >
< span class =code-keyword>< DataTemplate >
< DataGrid

名称 = objInnerDatagrid

ItemsSource = {Binding JobParts} > < / DataGrid >
< / DataTemplate >
< / DataGrid.RowDetailsTemplate >
< / DataGrid >

提前致谢!

解决方案

原始网格视图不适合分层呈现数据;并且像这样嵌套控件的想法效率不高。但是,一些高度定制的控件可以更好地完成这些操你可以在开源中找到一些。



例如,你可以考虑这个: https://wpftoolkit.codeplex.com/wikipage?title=Advanced%20DataGrid [ ^ ]。



这是基于列表视图的替代方案:WPF TreeListView控件 [ ^ ]。



您可以尝试查找其他内容。我建议这个相当复杂的查询: http://bit.ly/1wmtIkG [ ^ ]。



-SA

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:

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:

<DataGrid

Name="objOuterDatagrid"

ItemsSource="{Binding Jobs}">
    <DataGrid.RowDetailsTemplate>
        <DataTemplate>
            <DataGrid

            Name="objInnerDatagrid"

            ItemsSource="{Binding JobParts}"></DataGrid>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
</DataGrid>

Thanks in advance!

解决方案

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


这篇关于如何使用1个DataSet,2个相关DataTable,1个DataGrid创建分层DataGrid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆