ControlCollection.RemoveAt Method

Removes the control at the specified index in the ControlCollection instance.

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

Syntax

'Declaration
Sub RemoveAt ( _
    index As Integer _
)
void RemoveAt(
    int index
)

Parameters

Exceptions

Exception Condition
ArgumentOutOfRangeException

Index is less than zero or index is equal to or greater than count.

Remarks

Controls that were added at design time cannot be removed from the ControlCollection instance. You can only use the RemoveAt method to remove controls added at run time.

Examples

The following code example adds a Button control and a MonthCalendar control to the worksheet. When the button is clicked, the code removes the MonthCalendar control specified by the index.

Private Sub ExcelControlRemoveAt()

    Dim Button2 As Microsoft.Office.Tools.Excel. _
        Controls.Button = Me.Controls.AddButton( _
        0, 0, 56.25, 17.25, "Button2")
    Dim MonthCalendar1 As Microsoft.Office.Tools. _
        Excel.Controls.MonthCalendar = Me.Controls. _
        AddMonthCalendar(0, 20, 75, 15, "MonthCalendar1")

    Button2.Text = "Remove" 

    AddHandler Button2.Click, AddressOf Button2_Click

End Sub  
Private Sub Button2_Click(ByVal sender As Object, ByVal e _
    As EventArgs)

    Me.Controls.RemoveAt(1)

End Sub
private void ExcelControlRemoveAt()
{

    Microsoft.Office.Tools.Excel.Controls.Button button2 =
        this.Controls.AddButton(0, 0, 56.25, 17.25,
        "button2");
    Microsoft.Office.Tools.Excel.Controls.MonthCalendar
         monthCalendar1 = this.Controls.AddMonthCalendar(
         0, 20, 75, 15, "monthCalendar1");
    button2.Text = "Remove";
    button2.Click += new EventHandler(button2_Click);
}

void button2_Click(object sender, EventArgs e)
{
    this.Controls.RemoveAt(1);
}

.NET Framework Security

See Also

Reference

ControlCollection Interface

Microsoft.Office.Tools.Excel Namespace