开发者

How do I display two tables in a data grid/tree view showing columns for both the parent and child tables (when child expanded)

开发者 https://www.devze.com 2023-02-05 19:08 出处:网络
I\'m trying to use a TreeView/DataGrid to display some data. I need to display columns for the top level items, but also display a header for the expanded level.

I'm trying to use a TreeView/DataGrid to display some data. I need to display columns for the top level items, but also display a header for the expanded level.

I have a dataset with two tables, e.g. Orders and Items, items has a foreign key to Orders.

How do I display two tables in a data grid/tree view showing columns for both the parent and child tables (when child expanded)

I'm trying to bind the dataset to the datagrid/tree view so that I show the list of orders.

The WinFrom DataGrid can show multiple tables from the DataSet:

How do I display two tables in a data grid/tree view showing columns for both the parent and child tables (when child expanded)

Which I set with:

dataGrid.DataSource = dataSet;
dataGrid.DataMember = "Orders";

Clicking the [+] expands the row to show the link:

How do I display two tables in a data grid/tree view showing columns for both the parent and child tables (when child expanded)

Following that link brings up the Items Table:

How do I display two tables in a data grid/tree view showing columns for both the parent and child tables (when child expanded)

What I'm after is a mix of both but in WPF:

How do I display two tables in a data grid/tree view showing columns for both the parent and child tables (when child expanded)

I've used a dataset for this example but I can massage my data into collections etc that WPF can use to display the data in the way I'm trying to achie开发者_如何学运维ve.

I've looked at the TreeListView which gives me the top level item headers, but I'm scratching my head trying to get the expanded items header to be shown. Could someone point me in the right direction, thanks.

Update I've come back to looking at this issue. As per @offapps-cory's answer I tried using a ListView with expander with a listview. 1st attempt:

How do I display two tables in a data grid/tree view showing columns for both the parent and child tables (when child expanded)

As you can see, it expanded in the cell :) I'm thinking maybe I can throw a treeview into the mix...


Could you instead use a ListBox with ListViews nested in the items? While I have not had ListViews nested, I have nested ListBoxes several levels deep to achieve some functionality that I needed.

I originally thought that one might do as you are asking by customizing the TreeViewItem template and the ItemsPresenter, but ItemsPresenter is expecting a Panel, and ListView is a control.

I would try creating a DataTemplate with a ListView/GridView in it and an expander. You may need to do some funny databinding to get it working, but I don't see why it wouldn't work.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号