vb如何删除list中的选项

先生成了一个list:A B C D AB AC AD BC BD CD ABC ABD ACD BCD ABCD
现在我要删除list中所有同时含有BC的选项,应如何实现

第1个回答  推荐于2017-09-01
Private Sub Command1_Click()
For i = 0 To List1.ListCount - 1
If InStr(List1.List(i), "BC") > 0 Then List1.RemoveItem i
Next
End Sub本回答被提问者采纳
第2个回答  2019-10-20
Private
Sub
Command1_Click()
List1.Clear
Dim
S()
S
=
Array("A",
"B",
"C",
"D",
"AB",
"AC",
"AD",
"BC",
"BD",
"CD",
"ABC",
"ABD",
"ACD",
"BCD",
"ABCD")
Dim
i
As
Integer
For
i
=
LBound(S)
To
UBound(S)
List1.AddItem
S(i)
Next
i
Label2.Caption
=
"当前有
"
&
List1.ListCount
&
"
条数据!"
End
Sub
Private
Sub
Command2_Click()
Dim
i
As
Integer
Label1.Caption
=
"下列值已被删除!"
For
i
=
List1.ListCount
-
1
To
0
Step
-1
If
InStr(List1.List(i),
"BC")
>
0
Then
Label1.Caption
=
Label1.Caption
&
vbCrLf
&
List1.List(i)
List1.RemoveItem
i
End
If
Next
i
Label2.Caption
=
"当前有
"
&
List1.ListCount
&
"
条数据!"
End
Sub
第3个回答  2009-07-07
for i= list1.listcount-1 to 0 step -1
if instr(list1.list(i),"BC")<>0 then
list1.remove(i)
endif
next
第4个回答  2019-07-29
用do
while循环
只要list1里面有bc就不退出。自己控制循环变量i就可以了。
第5个回答  2019-08-07
like也能实现。
Private
Sub
Command1_Click()
For
i
=
List1.ListCount
-
1
To
1
Step
-1
If
List1.List(i)
Like
"*BC*"
Then
List1.RemoveItem
i
Next
i
End
Sub
Private
Sub
Form_Load()
List1.AddItem
"A"
List1.AddItem
"B"
List1.AddItem
"C"
List1.AddItem
"D"
List1.AddItem
"AB"
List1.AddItem
"AC"
List1.AddItem
"AD"
List1.AddItem
"BC"
List1.AddItem
"BD"
List1.AddItem
"CD"
List1.AddItem
"ABC"
List1.AddItem
"ABD"
List1.AddItem
"ACD"
List1.AddItem
"BCD"
List1.AddItem
"ABCD"
End
Sub
相似回答