Setting Up Hierarchical Data Views
ComponentOne Grid for WPF supports automatic hierarchical data representation; so, for example, when the grid is bound to a table with a child table, users can expand the child table under the current table to see related data. See Viewing Child Tables for information about interacting with child grids.
In hierarchical data views, the item type of the parent collection should contain a public property returning a child collection. For the grid to see this property and generate a corresponding Column automatically, the parent collection, such as the parent ObservableCollection must have a typed indexer, such as ObservableCollection<MyParentItem> instead of ObservableCollection<object>. If, for some reason, you must use ObservableCollection<object>, then a Column representing the child collection property must be added to the Columns collection explicitly.
Child tables will automatically be generated if the AutoGenerateColumns property is set to True. If AutoGenerateColumns is set to False, you can explicitly define a child grid using the Columns property. Simply define a Column with the PropertyName property set to a name of a data source item's property representing a child collection. If dealing with an ADO.NET DataSet, this should be the name of the DataRelation joining the parent and the child tables. For example, the following XAML defines the Order Details table in the Products Data Set:
<c1grid:C1DataGrid Name="c1DataGrid1" ItemsSource="{Binding Path=ProductsDataSet.Products, ElementName=window, Mode=Default}" AutoGenerateColumns="False">
<c1grid:C1DataGrid.Columns>
<c1grid:Column PropertyName="ProductsOrder Details" Caption="Ordered Products"/>
</c1grid:C1DataGrid.Columns>
</c1grid:C1DataGrid>
You can hide child tables by setting the AllowHierarchicalData property to False. For an example, see Hiding Child Tables.
You can customize a child grid by assigning a Style defining child grid properties to the ChildGridStyle property. For example, for child grid without a filter bar and with only two columns, the column definition in the above example should be changed to the following:
<c1grid:Column PropertyName="ProductsOrder Details" Caption="Ordered Products"/>
<c1grid:Column.ChildGridStyle>
<Style TargetType="c1grid:C1DataGrid">
<Setter Property="AutoGenerateColumns" Value="False"/>
<Setter Property="Columns">
<Setter.Value>
<c1grid:ColumnCollection>
<c1grid:Column PropertyName="UnitPrice" Caption="Price"/>
<c1grid:Column PropertyName="Quantity"/>
</c1grid:ColumnCollection>
</Setter.Value>
</Setter>
<Setter Property="FilterBarVisibility" Value="Collapsed"/>
</Style>
</c1grid:Column.ChildGridStyle>
</c1grid:Column>
You may also define a Style that will be applied to all child grids of the parent grid by assigning the Style to the ChildGridStyle property of the parent grid.
|