Table of contents
TOC
折叠目录
展开目录

ListBox.RemoveItem 方法 (访问)ListBox.RemoveItem Method (Access)

office 365 dev account|上次更新日期: 2018/3/13
|
2 参与人员

从指定的列表框控件显示的值列表中删除一项。Removes an item from the list of values displayed by the specified list box control.

语法Syntax

表达式RemoveItem(* 索引)expression. **RemoveItem( ** Index* )

表达式_表示一个列表框对象变量。_expression A variable that represents a ListBox object.

参数Parameters

名称Name必需/可选Required/Optional数据类型Data Type说明Description
IndexIndex必需RequiredVariantVariant要从列表中删除的项,用项的编号或列表项文本表示。The item to be removed from the list, expressed as either an item number or the list item text.

注解Remarks

此方法仅对窗体上列表框或组合框控件有效。此外,该控件的行来源类型属性必须设置为"值列表"。This method is only valid for list box or combo box controls on forms. Also, the RowSourceType property of the control must be set to "Value List".

列表项编号从零开始。如果_Index_参数的值不符合现有项目编号或现有项的文本,则会导致出错。List item numbers start from zero. If the value of the Index argument doesn't correspond to an existing item number or the text of an existing item, an error occurs.

使用AddItem方法将项添加到值列表中。Use the AddItem method to add items to the list of values.

示例Example

本示例删除列表框控件中列表的指定的项。要处理的函数,您必须将其传递表示在窗体和一个variant 类型值,表示要移除的项的列表框控件的列表框对象。This example removes the specified item from the list in a list box control. For the function to work, you must pass it a ListBox object representing a list box control on a form and a Variant value representing the item to be removed.

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

另请参阅See also

概念Concepts

ListBox 对象ListBox Object

© 2018 Microsoft