Udostępnij za pośrednictwem


ListObject.DataBoundFormat Property (2007 System)

Gets or sets the format style for data-bound ListObject controls.

Namespace:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel.v9.0 (in Microsoft.Office.Tools.Excel.v9.0.dll)

Syntax

'Declaration
Public Property DataBoundFormat As XlRangeAutoFormat
'Usage
Dim instance As ListObject 
Dim value As XlRangeAutoFormat 

value = instance.DataBoundFormat

instance.DataBoundFormat = value
public XlRangeAutoFormat DataBoundFormat { get; set; }
public:
property XlRangeAutoFormat DataBoundFormat {
    XlRangeAutoFormat get ();
    void set (XlRangeAutoFormat value);
}
public function get DataBoundFormat () : XlRangeAutoFormat 
public function set DataBoundFormat (value : XlRangeAutoFormat)

Property Value

Type: XlRangeAutoFormat
One of the XlRangeAutoFormat values.

Remarks

The ListObject control must be bound to data before you can use this property.

The specified format is applied to the entire list object, including rows that are added later.

To remove formatting, set DataBoundFormat to xlRangeAutoFormatNone.

Use DataboundFormatSettings to exclude specific types of formatting such as pattern, font, or width from the style.

Examples

The following code example creates a DataTable and a ListObject, and binds the ListObject to the DataTable. It then uses an XlRangeAutoFormat value to format the ListObject.

This example is for a document-level customization.

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", missing], "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;
}

.NET Framework Security

See Also

Reference

ListObject Class

ListObject Members

Microsoft.Office.Tools.Excel Namespace