RemoveItem 方法

此頁沒有內(nèi)容條目
內(nèi)容

從指定的列表框控件或組合框控件顯示的值列表中,刪除一個(gè)項(xiàng)。

expression.RemoveItem(Index)

expression     必需。返回“應(yīng)用于”列表中的一個(gè)對(duì)象的表達(dá)式。

Index     必需 Variant 型。即將從列表中刪除的項(xiàng),用項(xiàng)目號(hào)或列表項(xiàng)文本表示。

說明

該方法僅對(duì)窗體上的列表框或組合框控件有效。而且,控件的 RowSourceType 屬性必須設(shè)為“值列表”。

列表項(xiàng)編號(hào)從零開始。如果 Index 參數(shù)的值與現(xiàn)有項(xiàng)目編號(hào)或現(xiàn)有項(xiàng)的文本不對(duì)應(yīng),則會(huì)出錯(cuò)。

使用 AddItem 方法可以將項(xiàng)目添加到值列表中。

示例

該示例從列表框控件的列表中刪除指定項(xiàng)。為使函數(shù)可以工作,必須為其傳遞一個(gè)代表窗體上列表框控件的 ListBox 對(duì)象及一個(gè)代表要?jiǎng)h除的項(xiàng)的 Variant 值。

Function RemoveListItem(ctrlListBox As ListBox, _

        ByVal varItem As Variant) As Boolean

    ' Trap for errors.

    On Error GoTo ERROR_HANDLER

    ' Remove the list box item and set the return value

    ' to True, indicating success.

    ctrlListBox.RemoveItem Index:=varItem

    RemoveListItem = True

    ' Reset the error trap and exit the function.

    On Error GoTo 0

    Exit Function

' Return False if an error occurs.

ERROR_HANDLER:

    RemoveListItem = False

End Function