急,listbox对相同的项只显示一次

black205 2007-12-10 04:03:30
在VB中listbox对相同的项只显示一次應該怎么樣做呢?哪位大俠告知一下,謝謝
...全文
54 点赞 收藏 6
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
YuLv 2007-12-11
SendMessage 的方法是最好的选择,楼上正确。
回复
Sandrer 2007-12-11
嘿嘿,来个API版,速度更快,不用循环


Const LB_ADDSTRING = &H180
Const LB_FINDSTRING = &H18F

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Dim lngIndex As Long
Dim strItem As String
strItem = "这个变量等于你要插入到ListBox中的值"
lngIndex = SendMessage(List1.hWnd, LB_FINDSTRING, -1, ByVal strItem) '这里设置-1,是表示从头开始查找
If lngIndex = -1 Then '等于-1则表示没有找到匹配项目
SendMessage List1.hWnd, LB_ADDSTRING, 0, ByVal strItem '增加项目到ListBox中
End If
回复
of123 2007-12-11
用这个参数:

Const LB_FINDSTRINGEXACT = &H1A2
回复
black205 2007-12-10
謝謝樓上的兄弟,在參考你給的程序下問題解決了,謝謝
回复
ZOU_SEAFARER 2007-12-10
Private Sub Command1_Click()
On Error Resume Next
Dim vntA As Variant
Dim colX As New Collection
Dim intILoop As Integer
vntA = Array("abc", "abd", "abc", "abe") '//there are two "abc"
For intILoop = 0 To UBound(vntA)
Call colX.Add(vntA(intILoop), vntA(intILoop))
Next

For intILoop = 1 To colX.Count
Me.List1.AddItem colX.Item(intILoop)
Next

End Sub
回复
东方之珠 2007-12-10
dim i as Long,j as long
For i=0 to File1.ListCount-1
if File1.Selected(i)=True then "凡是选中的就添加(不能重复)
for j=0 to List1.ListCount-1
if trim(List1.List(j)) < >trim(File1.List(i)) then
List1.AddItem File1.List(i)
List1.refresh
endif
next
endif
next
回复
发动态
发帖子
VB基础类
创建于2007-09-28

7453

社区成员

VB 基础类
申请成为版主
社区公告
暂无公告