Back to Devexpress

GridControl.DataMember Property

windowsforms-devexpress-dot-xtragrid-dot-gridcontrol-61b3b3b5.md

latest7.3 KB
Original Source

GridControl.DataMember Property

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

Declaration

csharp
[DefaultValue("")]
[DXCategory("Data")]
public virtual string DataMember { get; set; }
vb
<DefaultValue("")>
<DXCategory("Data")>
Public Overridable Property DataMember As String

Property Value

TypeDefaultDescription
StringString.Empty

A string value representing the data source member.

|

Remarks

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).

Example

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.

csharp
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;
}
vb
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

csharp
gridControl1.DataSource = null;
gridControl1.DataMember = null;
gridView1.Columns.Clear();

winforms-richedit-in-an-active-grid-cell/CS/Form1.cs#L51

csharp
gridControl1.DataSource = ds;
    gridControl1.DataMember = ds.Tables[0].TableName;
}

winforms-grid-create-configure-sql-data-source/CS/dxSample/Form1.cs#L30

csharp
Grid.DataSource = ds;
    Grid.DataMember = "customQuery1";
}

winforms-grid-bind-to-azure-sql-database/CS/DXApplication1/Main.cs#L20

csharp
gridControl.DataSource = await SqlDataSourceProvider.Instance.GetDataAsync();
gridControl.DataMember = "AzureQuery";
gridView.BestFitColumns();

winforms-grid-customize-filter-criteria-before-apply/CS/FilterEvent/Form1.cs#L25

csharp
this.GridControl.DataSource = ds;
this.GridControl.DataMember = "Orders";
this.GridView.ActiveFilterCriteria = CriteriaOperator.Parse("Freight > 0");

winforms-query-builder/VB/Form1.vb#L30

vb
gridControl1.DataSource = Nothing
gridControl1.DataMember = Nothing
gridView1.Columns.Clear()

winforms-richedit-in-an-active-grid-cell/VB/Form1.vb#L46

vb
gridControl1.DataSource = ds
    gridControl1.DataMember = ds.Tables(0).TableName
End Sub

winforms-grid-create-configure-sql-data-source/VB/dxSample/Form1.vb#L36

vb
Grid.DataSource = ds
    Grid.DataMember = "customQuery1"
End Sub

winforms-grid-bind-to-azure-sql-database/VB/DXApplication1/Main.vb#L22

vb
gridControl.DataSource = Await SqlDataSourceProvider.Instance.GetDataAsync()
gridControl.DataMember = "AzureQuery"
gridView.BestFitColumns()

winforms-grid-customize-filter-criteria-before-apply/VB/FilterEvent/Form1.vb#L22

vb
GridControl.DataSource = ds
GridControl.DataMember = "Orders"
GridView.ActiveFilterCriteria = CriteriaOperator.Parse("Freight > 0")

See Also

Data Binding

MainView

GridControl Class

GridControl Members

DevExpress.XtraGrid Namespace