Share via


ListObject.Delete Method

Definition

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

public:
 void Delete();
public void Delete ();
abstract member Delete : unit -> unit
Public Sub Delete ()

Examples

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.

This example is for a document-level customization.

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();
    }
}
Private Sub ListObject_Delete()
    Dim List1 As Microsoft.Office.Tools.Excel.ListObject = _
        Me.Controls.AddListObject(Me.Range("A1", "D4"), "List1")

    If DialogResult.Yes = MessageBox.Show("Delete the ListObject?", _
        "Test", MessageBoxButtons.YesNo) Then
        List1.Delete()
    End If

End Sub

Remarks

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.)

Applies to