Data Binding Common Concepts
- 4 minutes to read
Data-aware DevExpress .NET controls use the common Microsoft .NET Framework data binding mechanism. To bind a data-aware control to data, you first need a data source - an object that retrieves data from its actual storage and passes it to a control.
DevExpress data-aware controls show data from their sources as is. If you need to filter or sort records, or merge multiple data sources into a single source, this should be done at the data source level before you bind the data-aware control to this source.
If a data source can return data as an object that implements the IList, IBindingList, or ITypedList interface, you can bind a DevExpress data-aware control to this source. For instance, the Entity Framework data access technology utilizes
System.Data.Entity.DbContext objects as sources. This source can return data loaded from a storage as a BindingList:
Since you can bind DevExpress data-aware controls to DbContext sources, this means that controls can display Entity Framework data.
Update Data-Aware Controls When Data Storages Change
DevExpress data-aware controls cannot track data storage changes, and do not automatically update their data. Two common approaches to update a data-aware control are as follows:
- create a “Refresh” button that relies on the data source API to reload data;
- add the
System.Windows.Forms.Timercomponent that uses the data source API to reload data whenever the
Depending on the data access technology and/or data source type, there are also other approaches. For instance, for SQL databases, you can use the
SqlDependency component and its
OnDependencyChange event. See the following Microsoft help topic for more information: Detecting Changes with SqlDependency.
Post Edited Data to Underlying Data Storages
DevExpress data-aware controls save edited data only to their sources. These changes are lost when the application restarts. To permanently save them, use the related data source API.
Data sources in Entity Framework and Entity Framework technologies (
DbContext objects) use the
SaveChanges method to post changes.
Depending on your scenario, you can call post changes:
- when a form closes - handle the Form.Closing event;
- when a user interacts with a designated UI element - handle the
Button.Clickor a similar event;
- immediately after the edit - handle the events indicated in the control’s corresponding help topic. For example, the following help topic explains how to save Data Grid control edits: Post Data to an Underlying Data Source.
Data Source Configuration Wizard
The Data Source Configuration Wizard is a DevExpress design-time tool that allows you to bind data-aware controls without a single line of code.
Supported Technologies and Data Sources
The list of supported data sources and data access technologies includes the following:
- Traditional Data Sources
- Azure SQL Databases
- Excel Data
- Entity Framework
- Entity Framework Core
- JSON Data
- LINQ to SQL Classes
- OData v2 and v4
- SQL Data
- WCF Data Services (Pivot Grid example)
- XML Data
- XPO Sources
To bind a control to data created at runtime, you can utilize one of the following two approaches:
- How to: Add Unbound Data to a Data-Aware Control
- How to: Bind GridControl to a Database and Implement Master-Detail Mode at Design Time
- How to: Bind a Control to a Database at Runtime
- How to: Bind a Control to Data Created at Runtime
- How to: Bind a Control to Data in an XML File
- How to: Add Virtual Rows Using the UnboundSource Component