WPF Data Grid: Bind to Data
- 3 minutes to read
Data Binding Basics
Do the following to bind the Grid to data:
- Use the ItemsSource property to bind the GridControl to data.
Manually create columns in XAML and use the FieldName and Binding properties to bind the columns to data.
Open the GridControl’s Quick Actions. Select Generate Columns to generate columns for each data field in XAML. The FieldName property is used to bind each column to data.
You can set the AutoGenerateColumns property to AddNew to generate and bind columns for all data fields at runtime, so you don’t have to define columns in XAML.
Implement CRUD Operations
To post user changes to the data source, implement CRUD operations (create, read, update, delete). Refer to the following topic for more information: CRUD Operations in a Data-Bound Grid.
The MVVM Support section describes how to bind the Data Grid to a view model.
Items Source Wizard
You can use the Items Source Wizard to bind the Grid to data. This wizard generates the data binding and CRUD code in XAML and code-behind.
The Items Source Wizard does not support ICollectionView and Microsoft Excel data sources.
Common Data Binding Scenarios
The following topics describe how to bind the WPF Data Grid to specific data sources:
- Local Collection
- Local Database
- Microsoft Excel Files
- Entity Framework Core
- XPO Data Sources
Large and Unknown Size Datasets
Server Mode and Instant Feedback Mode
The Data Grid includes Server Mode and Instant Feedback Mode designed specifically for large data sources.
The following data sources support Server Mode and Instant Feedback Mode:
Data Access Technology
Server Mode Data Source
Instant Feedback UI Data Source
Entity Framework 4+
eXpress Persistent Objects
WCF Data Services
LINQ to SQL
Parallel LINQ to Objects
Refer to the following topic for more information: Server Data and Large Data Sources.
You can use Virtual Sources to implement server-side processing for the Data Grid.
Virtual sources are compatible with any data source that exposes an API to fetch portions of data consecutively. Supported data sources include REST Services, NoSQL Databases, Custom WCF Services, EntityFramework, or any other ORM. Virtual sources do not require a total item count, and sorting, filtering, and summary calculation operations are optional.
The following tutorial describes how to use the Items Source Wizard to implement a virtual source: Bind the WPF Data Grid to Virtual Sources.
Frequently Updated Sources
If you need to implement a responsive user interface that is refreshed with real-time data, use the RealTimeSource component.
Custom (Unstructured) Data
The UnboundDataSource component is designed for binding scenarios when no strongly typed data set is available at compile time.
The GridControl supports a variety of techniques to bind to data that changes its structure at runtime. Refer to the following example for more information:
The following example illustrates how to bind the WPF Data Grid to different data source types:
This example includes multiple solutions that demonstrate:
- How to bind the Data Grid to Entity Framework, Entity Framework Core, and XPO.
- Different binding mechanisms: virtual sources, server mode sources, and local data.
- MVVM and code-behind patterns.