Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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.

Dataset from Visual Studio

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:

Data Grid Example

Which I set with:

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

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

Expanded DataGrid

Following that link brings up the Items Table:

DataGrid Items shown

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

Merged

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 achieve.

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:

enter image description here

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

like image 538
John Warlow Avatar asked Dec 06 '25 16:12

John Warlow


1 Answers

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.

like image 199
CodeWarrior Avatar answered Dec 08 '25 13:12

CodeWarrior



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!