在vb中,如何通过一个按钮把一个文本框的内容添加列表框中时,但是列表框中的内容不重复
答案:4 悬赏:70
解决时间 2021-02-06 16:35
- 提问者网友:夜微涼
- 2021-02-05 21:26
在vb中,如何通过一个按钮把一个文本框的内容添加列表框中时,但是列表框中的内容不重复
最佳答案
- 二级知识专家网友:眠于流年
- 2021-02-05 23:00
思路是在添加前加判断,是否存在
Private Sub Command1_Click()
Dim i As Integer
For i = 0 To List1.ListCount -1
If List1.List(i)=TextBox1.Text Then
MessageBox "此内容已经添加过了,不能重复添加!"
Exit Sub
End If
Next
List1.AddItem TextBox1.Text
End Sub
Private Sub Command1_Click()
Dim i As Integer
For i = 0 To List1.ListCount -1
If List1.List(i)=TextBox1.Text Then
MessageBox "此内容已经添加过了,不能重复添加!"
Exit Sub
End If
Next
List1.AddItem TextBox1.Text
End Sub
全部回答
- 1楼网友:茫然不知崩溃
- 2021-02-06 01:46
楼上153333的基本是正确的,只是 List1.AddItem TextBox1.Text 这一句,应该写在Next后面,不是在前面。
- 2楼网友:万千宠爱
- 2021-02-06 00:20
'在添加前加判断,是否存在
Private Sub Command1_Click()
Dim i As Integer
For i = 0 To List1.ListCount -1
If List1.List(i)=TextBox1.Text Then
MessageBox "不能重复添加!"
Exit Sub
End If
Next
List1.AddItem TextBox1.Text
End Sub
PS:小李无刀 -:)
- 3楼网友:怪咖小青年
- 2021-02-06 00:01
private sub command1_click()
dim f as boolean,i as integer
f=true
for i=0 to combo1.listindex-1
if text1.text=combo1.list(i) then f=false:exit for
next
if f then combo1.additem text1.text
end sub
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯
• 手机登qq时,显示手机磁盘不足,清理后重新登 |
• 刺客的套装怎么选啊? |