Share via


Proprietà ListObject.DataBoundFormat

Ottiene o imposta lo stile di formattazione per i controlli ListObject associati a dati.

Spazio dei nomi:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel (in Microsoft.Office.Tools.Excel.dll)

Sintassi

'Dichiarazione
Property DataBoundFormat As XlRangeAutoFormat
XlRangeAutoFormat DataBoundFormat { get; set; }

Valore proprietà

Tipo: Microsoft.Office.Interop.Excel.XlRangeAutoFormat
Uno dei valori di XlRangeAutoFormat.

Note

Per poter utilizzare questa proprietà, è necessario associare dapprima il controllo ListObject ai dati.

Il formato specificato viene applicato all'intero oggetto List, incluse le righe aggiunte in un secondo momento.

Per rimuovere la formattazione, impostare la proprietà DataBoundFormat su xlRangeAutoFormatNone.

Utilizzare la proprietà DataBoundFormatSettings per escludere tipi specifici di formattazione dallo stile, quali il motivo, il tipo di carattere o la larghezza.

Esempi

Nell'esempio di codice riportato di seguito viene creato un oggetto DataTable e un controllo ListObject, quindi viene eseguita l'associazione tra il controllo ListObject e l'oggetto DataTable. Viene infine utilizzato un valore di XlRangeAutoFormat per formattare il controllo ListObject.

Questo esempio è valido per una personalizzazione a livello di documento.

    Private Sub ListObject_DataBoundFormat()
        ' Create a new DataSet and DataTable.
        Dim ds As New DataSet()
        Dim dt As DataTable = ds.Tables.Add("Customers")
        dt.Columns.Add(New DataColumn("LastName"))
        dt.Columns.Add(New DataColumn("FirstName"))

        ' Add a new row to the DataTable.
        Dim dr As DataRow = dt.NewRow()
        dr("LastName") = "Chan"
        dr("FirstName") = "Gareth"
        dt.Rows.Add(dr)

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

        ' Bind the list object to the DataTable.
        List1.AutoSetDataBoundColumnHeaders = True
        List1.SetDataBinding(ds, "Customers", _
            "LastName", "FirstName")

        ' Add a format to the list object.
        List1.DataBoundFormat = _
            Excel.XlRangeAutoFormat.xlRangeAutoFormatList2

    End Sub

private void ListObject_DataBoundFormat()
{
    // Create a new DataSet and DataTable.
    DataSet ds = new DataSet();
    DataTable dt = ds.Tables.Add("Customers");
    dt.Columns.Add(new DataColumn("LastName"));
    dt.Columns.Add(new DataColumn("FirstName"));

    // Add a new row to the DataTable.
    DataRow dr = dt.NewRow();
    dr["LastName"] = "Chan";
    dr["FirstName"] = "Gareth";
    dt.Rows.Add(dr);

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

    // Bind the list object to the DataTable.
    list1.AutoSetDataBoundColumnHeaders = true;
    list1.SetDataBinding(ds, "Customers", "LastName",
        "FirstName");

    // Add a format to the list object.
    list1.DataBoundFormat = 
        Excel.XlRangeAutoFormat.xlRangeAutoFormatList2;
}

Sicurezza di .NET Framework

Vedere anche

Riferimenti

ListObject Interfaccia

Spazio dei nomi Microsoft.Office.Tools.Excel