windowsforms-2395-common-features-data-binding-common-concepts.md
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:
var data = dbContext.Customers.Local.ToBindingList();
Dim 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.
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:
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.
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");
sqlDataAdapter1.Update(myDataSet, "MyTable")
Data sources in Entity Framework and its technologies (DbContext objects) use the SaveChanges method to post changes.
dbContext.SaveChanges();
dbContext.SaveChanges()
You can post changes at any time, but typically you should save user edits during the following events:
Button.Click or a similar event.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.
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:
DevExpress WinForms UI controls share the same data binding techniques. Read the following quick-reference guides for detailed information and examples:
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