Files
docs-desktop/dotnet-desktop-guide/framework/winforms/data-sources-supported-by-windows-forms.md
T

7.1 KiB

title, ms.date, helpviewer_keywords, ms.assetid
title ms.date helpviewer_keywords ms.assetid
Supported Data Sources 03/30/2017
collections [Windows Forms], binding to
OLE DB providers [Windows Forms], Windows Forms
DataTable class [Windows Forms], binding and Windows Forms
Windows Forms, data binding
DataView class [Windows Forms], binding and Windows Forms
DataViewManager class [Windows Forms], binding and Windows Forms
Windows Forms, source data
arrays [Windows Forms]
data sources [Windows Forms]
data providers [Windows Forms]
DataSet class [Windows Forms], binding and Windows Forms
data [Windows Forms], data providers
3d2c43f6-462b-4d35-9c86-13e9afe012e1

Data Sources Supported by Windows Forms

Traditionally, data binding has been used within applications to take advantage of data stored in databases. With Windows Forms data binding, you can access data from databases as well as data in other structures, such as arrays and collections, so long as certain minimum requirements have been met.

Structures to Bind To

In Windows Forms, you can bind to a wide variety of structures, from simple objects (simple binding) to complex lists such as ADO.NET data tables (complex binding). For simple binding, Windows Forms supports binding to the public properties on the simple object. Windows Forms list-based binding generally requires that the object support the xref:System.Collections.IList interface or the xref:System.ComponentModel.IListSource interface. Additionally, if you are binding with through a xref:System.Windows.Forms.BindingSource component, you can bind to an object that supports the xref:System.Collections.IEnumerable interface. For more information about interfaces related to data binding, see Interfaces Related to Data Binding.

The following list shows the structures you can bind to in Windows Forms.

xref:System.Windows.Forms.BindingSource
A xref:System.Windows.Forms.BindingSource is the most common Windows Forms data source and acts a proxy between a data source and Windows Forms controls. The general xref:System.Windows.Forms.BindingSource usage pattern is to bind your controls to the xref:System.Windows.Forms.BindingSource and bind the xref:System.Windows.Forms.BindingSource to the data source (for example, an ADO.NET data table or a business object). The xref:System.Windows.Forms.BindingSource provides services that enable and improve the level of data binding support. For example, Windows Forms list based controls such as the xref:System.Windows.Forms.DataGridView and xref:System.Windows.Forms.ComboBox do not directly support binding to xref:System.Collections.IEnumerable data sources however, you can enable this scenario by binding through a xref:System.Windows.Forms.BindingSource. In this case, the xref:System.Windows.Forms.BindingSource will convert the data source to an xref:System.Collections.IList.

Simple objects
Windows Forms supports data binding control properties to public properties on the instance of an object using the xref:System.Windows.Forms.Binding type. Windows Forms also supports binding list based controls, such as a xref:System.Windows.Forms.ListControl to an object instance when a xref:System.Windows.Forms.BindingSource is used.

array or collection
To act as a data source, a list must implement the xref:System.Collections.IList interface; one example would be an array that is an instance of the xref:System.Array class. For more information on arrays, see How to: Create an Array of Objects (Visual Basic).

In general, you should use xref:System.ComponentModel.BindingList%601 when you create lists of objects for data binding. xref:System.ComponentModel.BindingList%601 is a generic version of the xref:System.ComponentModel.IBindingList interface. The xref:System.ComponentModel.IBindingList interface extends the xref:System.Collections.IList interface by adding properties, methods and events necessary for two-way data binding.

xref:System.Collections.IEnumerable
Windows Forms controls can be bound to data sources that only support the xref:System.Collections.IEnumerable interface if they are bound through a xref:System.Windows.Forms.BindingSource component.

ADO.NET data objects
ADO.NET provides a number of data structures suitable for binding to. Each varies in its sophistication and complexity.

See also