Skip to main content

XtraReportBase.DataMember Property

Gets or sets a specific list in a report’s data source.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v22.1.dll

Declaration

[DefaultValue("")]
[SRCategory(ReportStringId.CatData)]
public string DataMember { get; set; }

Property Value

Type Default Description
String

String.Empty

A String representing a list in a report’s XtraReportBase.DataSource.

Remarks

The DataMember property specifies the list (the object of a class that implements either the IList or the IListSource interface) in the data source that is returned by the XtraReportBase.DataSource property. Note that for the XtraReport object, this property’s value is usually a data table, and for the DetailReportBand this property’s value is a master-detail relationship.

After you assign a new object to the report’s DataSource property, the DataMember property is set to Empty. Set DataMember to the data member name before you use the newly assigned data source.

See the following topics for more information:

Example

The following code example illustrates how to bind a report to the Northwind database’s Products table and display product names:

using System.Windows.Forms;
using System;
using DevExpress.DataAccess.Sql;
using DevExpress.DataAccess.ConnectionParameters;
using DevExpress.XtraReports.UI;

// ...
private SqlDataSource BindToData() {
    // Create a data source that retrieves data from an XML file.  
    XmlFileConnectionParameters connectionParameters =
        new XmlFileConnectionParameters(@"C:\Users\Public\Documents\DevExpress Demos 21.2\Components\Data\nwind.xml");
    SqlDataSource dataSource = new SqlDataSource(connectionParameters);

    // Build a query that retrieves product names.
    SelectQuery query = SelectQueryFluentBuilder
        .AddTable("Products")
        .SelectColumn("ProductName")
        .Build("Products");

    // Add this query to the data source.
    dataSource.Queries.Add(query);

    // Populate the data source with data.
    dataSource.Fill();

    return dataSource;
}

private XtraReport CreateReport() {
    // Create a new report instance.
    XtraReport report = new XtraReport();

    // Assign a data source to the created report.
    report.DataSource = BindToData();
    report.DataMember = "Products";

    // Add a detail band to the report.
    DetailBand detailBand = new DetailBand();
    detailBand.Height = 50;
    report.Bands.Add(detailBand);

    // Create a new label.
    XRLabel label = new XRLabel { WidthF = 300 };
    // Bind the created label to the ProductName data field.
    label.ExpressionBindings.Add(new ExpressionBinding("Text", "[ProductName]"));
    // Add the label to the detail band.
    detailBand.Controls.Add(label);

            return report;
}

private void exportButton_Click(object sender, EventArgs e) {
    // Export the report to DOCX and save the exported file to the application folder.
    XtraReport report = CreateReport();
    report.ExportToDocx(report.Name + ".docx");
}

private void printButton_Click(object sender, EventArgs e) {
    // Send the report to the default printer.
    XtraReport report = CreateReport();
    report.Print();
}

Implements

See Also