diff --git a/Readme.md b/Readme.md index c5f8a09..955c267 100644 --- a/Readme.md +++ b/Readme.md @@ -1,20 +1,32 @@ - -![](https://img.shields.io/endpoint?url=https://codecentral.devexpress.com/api/v1/VersionRange/128578327/21.1.5%2B) -[![](https://img.shields.io/badge/Open_in_DevExpress_Support_Center-FF7200?style=flat-square&logo=DevExpress&logoColor=white)](https://supportcenter.devexpress.com/ticket/details/T615806) -[![](https://img.shields.io/badge/📖_How_to_use_DevExpress_Examples-e9f6fc?style=flat-square)](https://docs.devexpress.com/GeneralInformation/403183) - - -*Files to look at*: - -* [DateDataSourceWrapper.cs](./CS/WpfApplication1/DateDataSourceWrapper.cs) (VB: [DateDataSourceWrapper.vb](./VB/WpfApplication1/DateDataSourceWrapper.vb)) -* [MainWindow.xaml](./CS/WpfApplication1/MainWindow.xaml) (VB: [MainWindow.xaml](./VB/WpfApplication1/MainWindow.xaml)) -* [MainWindow.xaml.cs](./CS/WpfApplication1/MainWindow.xaml.cs) (VB: [MainWindow.xaml.vb](./VB/WpfApplication1/MainWindow.xaml.vb)) - -# How to add custom Field Values (Rows/Columns) that are not present in a DataSource - - -This is a WPF version of the How to add custom Field Values (Rows/Columns) that are not present in a DataSource example.

PivotGridControl does not display field values in row and column areas if these values are not represented in the underlying datasource. As a workaround, add all required values to the original datasource or create a datasource wrapper that contains all required values on its level, and there is no need to modify original datasource. 
This example illustrates how to create such a datasource wrapper. It is based on the How to create a data source wrapper that adds an empty item to the lookup list example.

In this example, the CustomDates collection is filled with DateTime values based on the actual Start/End DateTime range and the specified interval (e.g., Month). This collection is passed to the DateDataSourceWrapper class instance along with the original data source collection (Table.DefaultView). The main idea of creating a custom wrapper class is to merge the CustomDates collection with the original data table without modifying the latter one. So, when PivotGridControl requests data using the common IList and ITypedList interface methods, wrapper returns data from the original collection or generates EmptyObjectPropertyDescriptor objects to return rows with null "Date" field values. For instance, check the DateDataSourceWrapper.this[int index] and DateDataSourceWrapper.GetItemProperties method implementations.

You can also check the following example that illustrates the ITypedList interface concept: How to: Implement the ITypedList Interface. - -
- - + +[![](https://img.shields.io/badge/Open_in_DevExpress_Support_Center-FF7200?style=flat-square&logo=DevExpress&logoColor=white)](https://supportcenter.devexpress.com/ticket/details/T615806) +[![](https://img.shields.io/badge/📖_How_to_use_DevExpress_Examples-e9f6fc?style=flat-square)](https://docs.devexpress.com/GeneralInformation/403183) + + +# How to Add Custom Field Values (Rows/Columns) that are not Present in a Data Source + +Pivot Grid does not display field values in row and column areas if these values are not represented in the underlying data source. This example demonstrates how to create a data source wrapper that contains merged values ​​from a data source and a custom collection. In the example, the `CustomDates` collection is filled with DateTime values based on the actual Start/End DateTime range and the specified interval (for example, `Month`). This collection is passed to the `DateDataSourceWrapper` class instance along with the original data source collection (`Table.DefaultView`). The `CustomDates` collection is merged with the original data table and you do not need to modify the data source. When Pivot Grid requests data with the common [IList](https://msdn.microsoft.com/en-us/library/system.collections.ilist(v=vs.110).aspx) and [ITypedList](https://msdn.microsoft.com/en-us/library/system.componentmodel.itypedlist(v=vs.110).aspx) interface methods, the `DateDataSourceWrapper` object returns data from the original collection or generates `EmptyObjectPropertyDescriptor` objects to return rows with null "Date" field values. + + +The following image illustrates a Pivot Grid that displays the custom `March` field value from the `CustomDates` collection along with field values from the data source: + + +![Pivot Grid - Custom Field Values](./images/custom-field-values.png) + + +## Files to Look at + +* [DateDataSourceWrapper.cs](./CS/WpfApplication1/DateDataSourceWrapper.cs) (VB: [DateDataSourceWrapper.vb](./VB/WpfApplication1/DateDataSourceWrapper.vb)) +* [MainWindow.xaml](./CS/WpfApplication1/MainWindow.xaml) (VB: [MainWindow.xaml](./VB/WpfApplication1/MainWindow.xaml)) +* [MainWindow.xaml.cs](./CS/WpfApplication1/MainWindow.xaml.cs) (VB: [MainWindow.xaml.vb](./VB/WpfApplication1/MainWindow.xaml.vb)) + +## Documentation + +[Fields](https://docs.devexpress.com/WPF/8024/controls-and-libraries/pivot-grid/fundamentals/fields) +## More Examples + +- [Pivot Grid for WinForms - How to Add Custom Field Values (Rows/Columns) that Are Not Present in a Data Source](https://github.com/DevExpress-Examples/how-to-add-custom-field-values-rows-columns-that-are-not-present-in-a-datasource-e4493) + +- [How to create a data source wrapper that adds an empty item to the lookup list](https://github.com/DevExpress-Examples/how-to-create-a-data-source-wrapper-that-adds-an-empty-item-to-the-lookup-list-e1180) + + diff --git a/images/custom-field-values.png b/images/custom-field-values.png new file mode 100644 index 0000000..390ac26 Binary files /dev/null and b/images/custom-field-values.png differ