Share via


ListObject.ListColumns Property

Definition

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

public:
 property Microsoft::Office::Interop::Excel::ListColumns ^ ListColumns { Microsoft::Office::Interop::Excel::ListColumns ^ get(); };
public Microsoft.Office.Interop.Excel.ListColumns ListColumns { get; }
member this.ListColumns : Microsoft.Office.Interop.Excel.ListColumns
Public ReadOnly Property ListColumns As ListColumns

Property Value

A ListColumns collection that represents all the columns in the ListObject control.

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

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.

Applies to