Providers of Data to Windows Forms
Classically, data binding was used within applications to take advantage of data stored in databases. Windows Forms data binding allows you to access data from databases as well as data in other structures, such as arrays and collections (assuming certain minimum requirements have been met).
What Can I Bind To?
In Windows Forms, you can bind to a wide variety of structures, from simple (arrays) to complex (data rows, data views, and so on). As a minimum, a bindable structure must support the IList interface. As structures are based on increasingly capable interfaces, they offer more features that you can take advantage of when data binding. The list below summarizes the type of structures (data containers) you can bind to and provides some notes about what data-binding features are supported.
You can bind to all of the objects below because they implement the IList interface or a more sophisticated interface that encapsulates the functionality of IList (such as the IBindingList or IEditableObject interfaces). For more information on interfaces related to data binding, see Interfaces Related to Data Binding.
- Array or Collection
- To act as a data source, a list must implement the IList interface; one example would be an array that is an instance of the System.Array class. For more information on arrays, see Creating Arrays of Objects. For more information on collections, see Relation of Objects to Each Other.
- ADO.NET Data Objects
- ADO.NET provides a number of data structures suitable for binding to. Each varies in its sophistication and complexity.
- DataColumn object — A DataColumn object is the essential building block of a DataTable, in that a number of columns comprise a table. Each DataColumn object has a DataType property that determines the kind of data the column holds (for example, the make of an automobile in a table describing cars). You can simple-bind a control (such as a TextBox control's Text property) to a column within a data table.
- DataTable object — A DataTable object is the representation of a table, with rows and columns, in ADO.NET. A data table contains two collections: DataColumn, representing the columns of data in a given table (which ultimately determine the kinds of data that can be entered into that table), and DataRow, representing the rows of data in a given table. You can complex-bind a control to the information contained in a data table (such as binding the DataGrid control to a data table). However, when you bind to a DataTable, you are a really binding to the table's default view.
- DataView object — A DataView object is a customized view of a single data table that may be filtered or sorted. A data view is the data "snapshot" used by complex-bound controls. You can simple- or complex-bind to the data within a data view, but be aware that you are binding to a fixed "picture" of the data rather than a clean, updating data source.
- DataSet object — A DataSet object is a collection of tables, relationships, and constraints of the data in a database. You can simple- or complex-bind to the data within a dataset, but be aware that you are binding to the DataSet's default DataViewManager (see below).
- DataViewManager object — A DataViewManager object is a customized view of the entire DataSet, analogous to a DataView, but with relations included. A DataViewSettings collection allows you to set default filters and sort options for any views that the DataViewManager has for a given table.