windowsforms-devexpress-dot-xtragrid-dot-gridcontrol-a111cae8.md
Gets or sets the grid control’s data source.
Namespace : DevExpress.XtraGrid
Assembly : DevExpress.XtraGrid.v25.2.dll
NuGet Packages : DevExpress.Win.Grid, DevExpress.Win.Navigation
[DefaultValue(null)]
[DXCategory("Data")]
public virtual object DataSource { get; set; }
<DefaultValue(Nothing)>
<DXCategory("Data")>
Public Overridable Property DataSource As Object
| Type | Default | Description |
|---|---|---|
| Object | null |
An object representing the grid control’s data source.
|
Refer to the Data Binding and Master-Detail Relationships topics for information on which objects can be assigned to the DataSource property.
After the DataSource property is set to null , the ColumnView.FocusedRowHandle of the GridControl.MainView is set to GridControl.InvalidRowHandle. After a new data source is assigned to the DataSource property, the ColumnView.FocusedRowHandle is set to 0, to refer to the first data record.
The code sample below illustrates how to bind the GridControl to XML data.
xmlDataSet.ReadXml(@".\products.xml");
gridControl1.DataSource = xmlDataSet.Tables["product"];
xmlDataSet.ReadXml(".\products.xml")
gridControl1.DataSource = xmlDataSet.Tables("product")
The following code snippets (auto-collected from DevExpress Examples) contain references to the DataSource property.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.
void FillScheduledJobListBox(IEnumerable<ScheduledJobCatalogItemDto> scheduledJobs) {
scheduledJobsGrid.DataSource = scheduledJobs;
scheduledJobsView.BestFitColumns();
winforms-mvvm-expenses-app/CS/MVVMExpenses/Views/Account/AccountsEditFormView.cs#L29
fluent.SetBinding(
gridControl1, gc => gc.DataSource, x => x.AccountTransactionDetails.Entities);
gridControl1.DataSource = source.ToList();
CreateFilterColumns();
winforms-gridlookupedit-multiple-item-selection/CS/Form1.cs#L109
private void InitGrid() {
popupGridControl1.DataSource = CreateList(5);
gridControl2.DataSource = CreateList(5);
winforms-grid-data-annotation-attributes/CS/GridDataAttributes/Form1.cs#L36
case "Company public info":
gridControl1.DataSource = GridSampleDataList.GetCompanyPublicInfo();
break;
Private Sub FillScheduledJobListBox(ByVal scheduledJobs As IEnumerable(Of ScheduledJobCatalogItemDto))
scheduledJobsGrid.DataSource = scheduledJobs
scheduledJobsView.BestFitColumns()
winforms-mvvm-expenses-app/VB/MVVMExpenses/Views/Account/AccountsEditFormView.vb#L29
fluent.SetObjectDataSourceBinding(accountBindingSource, Function(x) x.Entity, Sub(x) x.Update())
fluent.SetBinding(GridControl1, Function(gc) gc.DataSource, Function(x) x.AccountTransactionDetails.Entities)
CType(GridControl1.MainView, DevExpress.XtraGrid.Views.Grid.GridView).Columns("Account").Visible = False
source = From product In products Where product.Quantity >= 20 Select product
gridControl1.DataSource = source.ToList()
CreateFilterColumns()
winforms-gridlookupedit-multiple-item-selection/VB/Form1.vb#L106
Private Sub InitGrid()
popupGridControl1.DataSource = CreateList(5)
gridControl2.DataSource = CreateList(5)
winforms-grid-data-annotation-attributes/VB/GridDataAttributes/Form1.vb#L33
Case "Company public info"
gridControl1.DataSource = GridSampleDataList.GetCompanyPublicInfo()
Case "Company private info"
See Also