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.

The diagram of a common binding concept

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.

Data Sources

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:

var data = dbContext.Customers.Local.ToBindingList();

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.Timer component that uses the data source API to reload data whenever the Timer.Tick event fires.

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.

For example, if a control is bound to a DataSet source that uses a DataAdapter to load data, use the adapter’s Update method.

sqlDataAdapter1.Update(myDataSet, "MyTable");

Data sources in Entity Framework and Entity Framework technologies (DbContext objects) use the SaveChanges method to post changes.

dbContext.SaveChanges();

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.Click or 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:

To bind a control to data created at runtime, you can utilize one of the following two approaches:

See Also

Examples