Skip to main content

Unbound Data

Unbound data can be "appended" to a data item through the use of unbound item properties, which are represented by the DataGridUnboundItemProperty class. Unlike unbound columns, which can be used to display non-data related information such as a label or controls that allow some sort of action to be carried out, unbound item properties can be used to provide additional data, such as calculated columns (see Example 1).

An item property's QueryValue event is raised for each data item in the underlying data source and allows unbound values to be provided for each item through the Value property received in the event arguments (see Example 1). The CommittingValue event is also raised for each data item to allow the unbound value to be committed, if required. In both cases, the item received in the event parameters represents the original data item without any unbound item property fields.

Like data-bound item properties, each unbound item property has its corresponding column (see Column class) in the grid's Columns collection, which can be used to define layout and behavioral information for the item property.

tip

Although both the UnboundColumn and DataGridUnboundItemProperty classes both use the term "unbound" they are not meant to be used together.

Examples

All examples in this topic assume that the grid is bound to the Products table of the Northwind database, unless stated otherwise

Example 1: Providing unbound data

The following example demonstrates how to add Person data to a custom ObservableCollection of Person objects.

<Grid xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid"
xmlns:local="clr-namespace:Xceed.Wpf.Documentation"
xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase">
<Grid.Resources>
<local:PersonObservableCollection x:Key="personData">
<local:Person FirstName="Jenny"
LastName="Beland"
Occupation="Writer"/>
<local:Person FirstName="Francois"
LastName="Carignan"
Occupation="Developer"/>
<local:Person FirstName="Pascal"
LastName="Bourque"
Occupation="Developer"/>
<local:Person FirstName="Michel"
LastName="Fortin"
Occupation="Developer"/>
<local:Person FirstName="Marc"
LastName="Laroche"
Occupation="Developer"/>
<local:Person FirstName="Pierre-Luc"
LastName="Ledoux"
Occupation="Developer"/>
<local:Person FirstName="Mathieu"
LastName="Drimonakos"
Occupation="TechnicalSupport"/>
<local:Person FirstName="Catherine"
LastName="Sauzede"
Occupation="Infograph"/>
</local:PersonObservableCollection>
<xcdg:DataGridCollectionViewSource x:Key="cvs_person"
ItemType="{x:Type local:Person}"
Source="{StaticResource personData}">
<xcdg:DataGridCollectionViewSource.GroupDescriptions>
<xcdg:DataGridGroupDescription PropertyName="Occupation"/>
</xcdg:DataGridCollectionViewSource.GroupDescriptions>
<xcdg:DataGridCollectionViewSource.SortDescriptions>
<scm:SortDescription PropertyName="Occupation"
Direction="Ascending"/>
</xcdg:DataGridCollectionViewSource.SortDescriptions>
</xcdg:DataGridCollectionViewSource>
</Grid.Resources>
<xcdg:DataGridControl x:Name="PersonGrid"
ItemsSource="{Binding Source={StaticResource cvs_person}}"/>
</Grid>