从指定的列表框控件显示的值列表中删除一项。
语法
表达式.RemoveItem(Index)
表达式 一个代表 ListBox 对象的变量。
参数
名称
|
必选/可选
|
数据类型
|
说明
|
Index
|
必选
|
Variant
|
要从列表中删除的项,用项的编号或列表项文本表示。
|
说明
此方法仅对窗体上的列表框或组合框控件有效。而且,控件的 RowSourceType 属性必须设置为“值列表”。
列表项的编号从零开始。如果 Index 参数的值与现有项目编号或现有项的文本不对应,则会出错。
使用 AddItem 方法可以向值列表中添加项。
示例
该示例从列表框控件的列表中删除指定项。为使函数可以工作,必须为其传递一个代表窗体上列表框控件的 ListBox 对象及一个代表要删除的项的 Variant 值。
Visual Basic for Applications
|
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
参考示例:列表框里加项和减项示例[Access软件网] http://www.accessoft.com/article-show.asp?id=2265
|