System.Windows.Forms.DataGridView.DataSource Property

Gets or sets the data source that the System.Windows.Forms.DataGridView is displaying data for.

Syntax

[System.ComponentModel.AttributeProvider(typeof(System.ComponentModel.IListSource))]
[System.ComponentModel.DefaultValue(null)]
[System.ComponentModel.RefreshProperties(System.ComponentModel.RefreshProperties.Repaint)]
public object DataSource { set; get; }

Value

Documentation for this section has not yet been entered.

Remarks

The System.Windows.Forms.DataGridView class supports the standard Windows Forms data-binding model. This means the data source can be of any type that implements one of the following interfaces:

For specific examples, see the Example section and the task table at the end of this section.

Typically, you will bind to a System.Windows.Forms.BindingSource component and bind the System.Windows.Forms.BindingSource component to another data source or populate it with business objects. The System.Windows.Forms.BindingSource component is the preferred data source because it can bind to a wide variety of data sources and can resolve many data binding issues automatically.

When binding to a data source that contains multiple lists or tables, you must set the DataGridView.DataMember property to a string that specifies the list or table to bind to. When binding to a System.Windows.Forms.BindingSource component that contains multiple lists or tables, however, you can set the BindingSource.DataMember property of the System.Windows.Forms.BindingSource component instead.

When binding to an object collection rather than to database data, you will typically set the DataGridViewCellStyle.DataSourceNullValue property of the object returned by the DataGridView.DefaultCellStyle property to null rather than using the default value of DBNull.Value, which is appropriate for database data.

For more information, see Displaying Data in the Windows Forms DataGridView Control. The following table provides direct links to common tasks related to the DataGridView.DataSource property.

dgv_datasource_tasks

Requirements

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Assembly Versions: 2.0.0.0
Since: .NET 2.0