DevExpress-Examples / wpf-bind-gridcontrol-to-dynamic-data

This example demonstrates how to bind GridControl to dynamic data in several different ways.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WPF Data Grid - Bind to Dynamic Data

This example demonstrates various techniques that allow you to bind the GridControl to data that changes its structure at runtime.

The Task

The GridControl is a data-aware control that displays data from a source collection. In most cases, this data is predetermined, and the GridControl uses its property descriptors to obtain data from a data source.

When data source values are calculated at runtime, they are placed in a collection with an arbitrary size. In this collection, the number of rows and columns can change. You cannot use predefined accessors for such values.

The Standard Technique

To perform this task, you can use the standard WPF data binding. Refer to the following help for information on how to use data bindings in the GridControl: Binding Columns to Data Source Fields.

In certain cases and with a large amount of data, bindings may cause performance issues. We recommend that you use bindings for columns only when it is necessary. For example, to display unsupported data formats with custom cell templates or to make the GridControl work with the interface inheritance.

The DevExpress Technique

Considerations

  • Use the ExpandoObject technique if you need to add fields to your data source at runtime.
  • The ICustomTypeDescriptor and ITypedList interfaces allow you to use custom property descriptors so you can change the way data is fetched from your data source.
  • Use the DataTable technique if you need to programmatically control rows and columns.

Comparison

Technique Complexity* Overall Performance (1M rows)** Sorting Filtering (even records) Scrolling
Unbound Columns (VB) Simple Average 1.5x 1.5x 0.4x
Virtual Data Source (VB)*** Average Good - - -
ExpandoObject (VB) Average Good 0.5x 1.4x 0.5x
ICustomTypeDescriptor (VB) Difficult Average 2x 1.5x 0.3x
ITypedList (VB) Difficult Average 1.5x 1.6x 0.4x
DataTable (VB) Simple Reduced 0.5x 3.8x 0.6x

* The complexity is mostly measured by our subjective opinion and the aggregate necessity to create custom classes, implement interfaces, or handle events.

** The exact time may differ based on the project implementation or machine specifications. This table shows relative values measured in multiple attempts on the same machine.

*** When you add new columns to a virtual data source at runtime, you should reset the source and fetch all rows. The performance of common data shaping operations depends on custom logic that implements such operations in the source.

Documentation

More Examples

About

This example demonstrates how to bind GridControl to dynamic data in several different ways.

License:Other


Languages

Language:Visual Basic .NET 50.6%Language:C# 49.4%