TreeView Mode in DataGrid?

Sep 12, 2008 at 6:04 PM
I am looking to display Hierarchical data in the DataGrid along with columns like this:

  ITEM       COLOR          PRICE
  ----------------------------------
  Apple           red                   $1
  Orange        Orange              $1
- Bag              Tan                  $6
    |_ Pen         Blue                 $1
    |_Eraser      Pink                 $1

I explored HierarchicalDataTemplates but could not get them to work with the DataGrid. 

Currently I am binding to an xml file that looks like this:

<Items>
    <Item Name="Apple" Color="Red" Price="$1" />
    <Item Name="Orange" Color="Orange" Price="$1" />
    <Item Name="Bag" Color="Tan" Price="$6" >
        <Item Name="Pen" Color="Blue" Price="$1" />
        <Item Name="Eraser" Color="Pink" Price="$1" />
    </Item>
</Items>

I'd appreciate any pointers getting hierarchical data to display in the DataGrid while retaining all the goodness of columns.
Sep 19, 2008 at 9:59 AM
I'm also interested in this feature.
Coordinator
Sep 22, 2008 at 7:39 PM
For this first release, the DataGrid will not have a tree mode. Tree behavior inside controls like DataGrid and ListView have been requested, and the controls and data team are aware of them and thinking of future solutions.

For now, getting a tree inside one of these controls requires writing or importing some custom control. I have a sample here that shows how to create a custom CollectionView that will flatten some groups. A similar concept could be used to flatten tree hierarchy, but the UI would still need to be implemented. You can also do a search for TreeListView. There are several implementations out there, and on of those might be useful.

Ben
Oct 19, 2008 at 7:55 PM
I was wondering if there is also a sample that shows how to host a datagrid in the new datagrid.
Dec 18, 2008 at 6:41 PM
Edited Dec 18, 2008 at 6:42 PM
I have been playing with the toolkit and it does not seem to allow you to have a datagrid as part of the details row, so trying to find a way to show hierarchy for parent child rows (like access does).  I found an example of how to do some form of hierarchy here http://msdn.microsoft.com/en-us/library/system.windows.hierarchicaldatatemplate.aspx.

Any samples for parent child details?
Coordinator
Dec 18, 2008 at 8:03 PM
I should be able to place a DataGrid in the row details of another DataGrid. Here's an example:
    <dg:DataGrid ItemsSource="{Binding Path=People,ElementName=TheWindow}"
                 RowDetailsVisibilityMode="Visible"
                 AutoGenerateColumns="False">
      <dg:DataGrid.Columns>
        <dg:DataGridTextColumn Header="First" Binding="{Binding Path=FirstName}" IsReadOnly="True" />
        <dg:DataGridTextColumn Header="Last" Binding="{Binding Path=LastName}" IsReadOnly="True"  />
      </dg:DataGrid.Columns>
      <dg:DataGrid.RowDetailsTemplate>
        <DataTemplate>
          <dg:DataGrid ItemsSource="{Binding Path=Friends}"
                       AutoGenerateColumns="False">
            <dg:DataGrid.Columns>
              <dg:DataGridTextColumn Header="First" Binding="{Binding Path=FirstName}" IsReadOnly="True" />
              <dg:DataGridTextColumn Header="Last" Binding="{Binding Path=LastName}" IsReadOnly="True"  />
            </dg:DataGrid.Columns>
          </dg:DataGrid>
        </DataTemplate>
      </dg:DataGrid.RowDetailsTemplate>
    </dg:DataGrid>
Dec 18, 2008 at 8:32 PM
I found my problem, I had added my datagrid to the wrong stackpanel. It was showing up somewhere I could not see at the time. It did not make sense it would not support it as a defined RowDetailsTemplate.