Partager via


ListObject.ListColumns Property

Gets a ListColumns collection that represents all the columns in the ListObject control.

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

Syntax

'Declaration
ReadOnly Property ListColumns As ListColumns
ListColumns ListColumns { get; }

Property Value

Type: Microsoft.Office.Interop.Excel.ListColumns
A ListColumns collection that represents all the columns in the ListObject control.

Remarks

To delete any items from this collection, do not use the Delete method of the item. Use the Delete method of the range of the item to delete the item; for example ListColumns.Item(1).Range.Delete(). Note that you cannot delete columns of a ListObject control that are bound to a data source.

Examples

The following code example creates a ListObject, gets the collection of columns, and then displays a message showing how many columns the ListObject contains.

This example is for a document-level customization.

Private Sub ListObject_ListColumns()
        Dim List1 As Microsoft.Office.Tools.Excel.ListObject = _
            Me.Controls.AddListObject(Me.Range("A1", "C4"), "List1")

        Dim List1Columns As Excel.ListColumns = List1.ListColumns
        MessageBox.Show("The list object contains " & _
            List1Columns.Count.ToString() & " columns.")
    End Sub
private void ListObject_ListColumns()
{
    Microsoft.Office.Tools.Excel.ListObject list1 = 
        this.Controls.AddListObject(
        this.Range["A1", "C4"], "list1");

    Excel.ListColumns list1Columns = list1.ListColumns;
    MessageBox.Show("The list object contains " + 
        list1Columns.Count.ToString() + " columns.");
}

.NET Framework Security

See Also

Reference

ListObject Interface

Microsoft.Office.Tools.Excel Namespace