windowsforms-devexpress-dot-xtragrid-dot-gridcontrol-61b3b3b5.md
Gets or sets a sub-list of the data source (GridControl.DataSource) whose data is supplied for the grid control’s main View.
Namespace : DevExpress.XtraGrid
Assembly : DevExpress.XtraGrid.v25.2.dll
NuGet Packages : DevExpress.Win.Grid, DevExpress.Win.Navigation
[DefaultValue("")]
[DXCategory("Data")]
public virtual string DataMember { get; set; }
<DefaultValue("")>
<DXCategory("Data")>
Public Overridable Property DataMember As String
| Type | Default | Description |
|---|---|---|
| String | String.Empty |
A string value representing the data source member.
|
This property is useful when binding to a data source containing several lists, tables or data relationships. In this case, set the GridControl.DataSource property to the aggregated data source and set the DataMember property to the name that identifies the desired table/list/data relationship. The specified data is supplied for the grid control’s main View (GridControl.MainView).
The code below binds the Data Grid to sample data stored in JSON format. This source contains the “root” element that includes two data tables: “Customers”, and “ResponseStatus”. The Grid displays data from the “Customers” table due to the DataMember property value.
private void Form1_Load(object sender, EventArgs e)
{
gridControl1.DataMember = "Customers";
gridControl1.DataSource = CreateDataSourceFromWeb();
}
private JsonDataSource CreateDataSourceFromWeb()
{
var jsonDataSource = new JsonDataSource();
//Specify the data source location
jsonDataSource.JsonSource = new UriJsonSource(new Uri("https://raw.githubusercontent.com/DevExpress-Examples/DataSources/master/JSON/customers.jso"));
jsonDataSource.Fill();
return jsonDataSource;
}
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
gridControl1.DataMember = "Customers"
gridControl1.DataSource = CreateDataSourceFromWeb()
End Sub
Private Function CreateDataSourceFromWeb() As JsonDataSource
Dim jsonDataSource = New JsonDataSource()
'Specify the data source location
jsonDataSource.JsonSource = New UriJsonSource(New Uri("https://raw.githubusercontent.com/DevExpress-Examples/DataSources/master/JSON/customers.jso"))
jsonDataSource.Fill()
Return jsonDataSource
End Function
The following code snippets (auto-collected from DevExpress Examples) contain references to the DataMember 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.
winforms-query-builder/CS/Form1.cs#L28
gridControl1.DataSource = null;
gridControl1.DataMember = null;
gridView1.Columns.Clear();
winforms-richedit-in-an-active-grid-cell/CS/Form1.cs#L51
gridControl1.DataSource = ds;
gridControl1.DataMember = ds.Tables[0].TableName;
}
winforms-grid-create-configure-sql-data-source/CS/dxSample/Form1.cs#L30
Grid.DataSource = ds;
Grid.DataMember = "customQuery1";
}
winforms-grid-bind-to-azure-sql-database/CS/DXApplication1/Main.cs#L20
gridControl.DataSource = await SqlDataSourceProvider.Instance.GetDataAsync();
gridControl.DataMember = "AzureQuery";
gridView.BestFitColumns();
winforms-grid-customize-filter-criteria-before-apply/CS/FilterEvent/Form1.cs#L25
this.GridControl.DataSource = ds;
this.GridControl.DataMember = "Orders";
this.GridView.ActiveFilterCriteria = CriteriaOperator.Parse("Freight > 0");
winforms-query-builder/VB/Form1.vb#L30
gridControl1.DataSource = Nothing
gridControl1.DataMember = Nothing
gridView1.Columns.Clear()
winforms-richedit-in-an-active-grid-cell/VB/Form1.vb#L46
gridControl1.DataSource = ds
gridControl1.DataMember = ds.Tables(0).TableName
End Sub
winforms-grid-create-configure-sql-data-source/VB/dxSample/Form1.vb#L36
Grid.DataSource = ds
Grid.DataMember = "customQuery1"
End Sub
winforms-grid-bind-to-azure-sql-database/VB/DXApplication1/Main.vb#L22
gridControl.DataSource = Await SqlDataSourceProvider.Instance.GetDataAsync()
gridControl.DataMember = "AzureQuery"
gridView.BestFitColumns()
winforms-grid-customize-filter-criteria-before-apply/VB/FilterEvent/Form1.vb#L22
GridControl.DataSource = ds
GridControl.DataMember = "Orders"
GridView.ActiveFilterCriteria = CriteriaOperator.Parse("Freight > 0")
See Also