Właściwość ListObject.DataMember —

Pobiera lub ustawia element członkowski określonych danych w źródle danych multimember powiązać z ListObject kontroli.

Przestrzeń nazw:  Microsoft.Office.Tools.Excel
Zestaw:  Microsoft.Office.Tools.Excel (w Microsoft.Office.Tools.Excel.dll)

Składnia

'Deklaracja
Property DataMember As String
string DataMember { get; set; }

Wartość właściwości

Typ: System.String
Członek danych ze źródła danych multimember.Wartością domyślną jest Empty.

Uwagi

Nie potrzebny, jeśli źródło danych zawiera tylko jeden element członkowski.

Użycie DataMember właściwości w celu określenia członka powiązać ze źródła danych multimember ListObject kontroli.Na przykład, jeśli masz źródła danych z więcej niż jednej tabeli określonej w DataSource właściwości, należy zastosować DataMember właściwość, aby określić, która tabela powiązać z ListObject kontroli.

Przykłady

Poniższy przykład kodu tworzy DataSet z dwoma DataTable obiekty i wypełnia jedną z tabel z danymi.Następnie ustawia kod DataSource i DataMember właściwości ListObject powiązać z tabeli, która zawiera dane.

W tym przykładzie jest dla dostosowania poziomu dokumentu.

    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

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";
}

Zabezpieczenia programu .NET Framework

Zobacz też

Informacje

ListObject Interfejs

Przestrzeń nazw Microsoft.Office.Tools.Excel