Export (0) Print
Expand All

ListObject.Delete Method

Deletes a dynamically created ListObject control, clears the cell data from the worksheet, and removes the control from the ControlCollection.

Namespace: Microsoft.Office.Tools.Excel
Assembly: Microsoft.Office.Tools.Excel (in microsoft.office.tools.excel.dll)

public void Delete ()

This method should only be used with a ListObject control that is created programmatically at run time. An exception is thrown if you call this method on a ListObject that is added to the document at design time.

If the list object is linked to a SharePoint site, deleting it does not affect data on the server that is running Windows SharePoint Services. Any uncommitted changes made to the local list object are not sent to the SharePoint list. (There is no warning that these uncommitted changes are lost.)

The following code example creates a ListObject on the current worksheet and then displays a message box that asks the user whether to delete the ListObject. If the user accepts, then the Delete method is called to remove the ListObject.

private void ListObject_Delete()
{
    Microsoft.Office.Tools.Excel.ListObject list1 =
        this.Controls.AddListObject(this.Range["A1", "D4"], "list1");

    if (DialogResult.Yes == MessageBox.Show("Delete the ListObject?",
        "Test", MessageBoxButtons.YesNo))
    {
        list1.Delete();
    }
}

Show:
© 2014 Microsoft