Skip to main content

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.

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 techniques 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 techniques. 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 save them permanently, 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 its technologies (DbContext objects) use the SaveChanges method to post changes.

dbContext.SaveChanges();

You can post changes at any time, but typically you should save user edits during the following events:

  • 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 a user edits a cell value - 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:

Cheat Sheets and Best Practices

DevExpress WinForms UI controls share the same data binding techniques. Read the following quick-reference guides for detailed information and examples:

Troubleshooting

Data binding issues are not usually related to DevExpress UI components directly. Read the following article for information on how to fix known issues:

Data Binding - DevExpress WinForms Troubleshooting

See Also

Examples