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)

ListColumns ListColumns { get; }

Property Value

Type: Microsoft.Office.Interop.Excel.ListColumns

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

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.

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.");
}
Return to top
Show: