ListObject.DataMember Property

Definition

Gets or sets the specific data member in a multimember data source to bind to the ListObject control.

public:
 property System::String ^ DataMember { System::String ^ get(); void set(System::String ^ value); };
public string DataMember { get; set; }
member this.DataMember : string with get, set
Public Property DataMember As String

Property Value

A data member from a multimember data source. The default value is Empty.

Examples

The following code example creates a DataSet with two DataTable objects and populates one of the tables with data. The code then sets the DataSource and DataMember properties of the ListObject to bind to the table that contains data.

This example is for a document-level customization.

private void ListObject_DataSourceAndMember()
{
    // Create a DataSet and two DataTables.
    DataSet ordersDataSet = new DataSet("ordersDataSet");
    DataTable tableCustomers = new DataTable("Customers");
    DataTable tableProducts = new DataTable("Products");
    ordersDataSet.Tables.Add(tableCustomers);
    ordersDataSet.Tables.Add(tableProducts);

    // Add a data to the Customers DataTable.
    tableCustomers.Columns.Add(new DataColumn("LastName"));
    tableCustomers.Columns.Add(new DataColumn("FirstName"));
    DataRow dr = tableCustomers.NewRow();
    dr["LastName"] = "Chan";
    dr["FirstName"] = "Gareth";
    tableCustomers.Rows.Add(dr);

    // Create a list object.
    Microsoft.Office.Tools.Excel.ListObject list1 = 
        this.Controls.AddListObject(
        this.Range["A1"], "Customers");

    // Bind the list object to the Customers table.
    list1.AutoSetDataBoundColumnHeaders = true;
    list1.DataSource = ordersDataSet;
    list1.DataMember = "Customers";
}
Private Sub ListObject_DataSourceAndMember()
    ' Create a DataSet and two DataTables.
    Dim ordersDataSet As New DataSet("ordersDataSet")
    Dim tableCustomers As New DataTable("Customers")
    Dim tableProducts As New DataTable("Products")
    ordersDataSet.Tables.Add(tableCustomers)
    ordersDataSet.Tables.Add(tableProducts)

    ' Add a data to the Customers DataTable.
    tableCustomers.Columns.Add(New DataColumn("LastName"))
    tableCustomers.Columns.Add(New DataColumn("FirstName"))
    Dim dr As DataRow = tableCustomers.NewRow()
    dr("LastName") = "Chan"
    dr("FirstName") = "Gareth"
    tableCustomers.Rows.Add(dr)

    ' Create a list object.
    Dim List1 As Microsoft.Office.Tools.Excel.ListObject = _
        Me.Controls.AddListObject(Me.Range( _
        "A1"), "Customers")

    ' Bind the list object to the Customers table.
    List1.AutoSetDataBoundColumnHeaders = True
    List1.DataSource = ordersDataSet
    List1.DataMember = "Customers"

End Sub

Remarks

Not needed if the data source has only one member.

Use the DataMember property to specify a member from a multimember data source to bind to the ListObject control. For example, if you have a data source with more than one table specified in the DataSource property, use the DataMember property to specify which table to bind to the ListObject control.

Applies to