This example demonstrates various techniques that allow you to bind the GridControl to data that changes its structure at runtime.
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.
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 GridControl can contain Unbound Columns. These columns can display any values and are suitable for dynamic data. Handle the CustomUnboundColumnData event to manually fetch and save edited data.
- You can also use our Virtual Data Sources for this task. Such sources support Custom Properties that allow you to define custom property descriptors.
- 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.
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.
- WPF Data Grid: Bind to Data
- Bind the WPF Data Grid to any Data Source with Virtual Sources
- Unbound Columns
(you will be redirected to DevExpress.com to submit your response)