集合中关键字不唯一 急!!!
Public Sub AddClientToLvw(ByVal objClient As Recordset, _ByRef lvw As ListView, _
ByVal IsOverWrite As Boolean)
Dim itm As ListItem
Dim sIcon As String
Dim bIcon As String
If objClient("clkSex") = Male Then
sIcon = "sboy"
bIcon = "bboy"
Else
sIcon = "sgirl"
bIcon = "bgirl"
End If
'如果是更新(即覆盖),则使用当前选种的元素
If IsOverWrite Then
Set itm = lvw.SelectedItem
If itm Is Nothing Then Exit Sub
Else
Set itm = lvw.ListItems.Add(, "A" & objClient("clkID"), , bIcon, sIcon)
End If
With objClient '这里要与InitClientListview相对应
itm.SmallIcon = sIcon
itm.Icon = bIcon
itm.Text = .Fields(1).Value
itm.SubItems(1) = IIf(.Fields(3).Value = Male, "男", "女")
itm.SubItems(2) = GetValueByID("Depart", "DepartId", .Fields(4).Value, "DName")
itm.SubItems(3) = .Fields(2).Value
itm.SubItems(4) = .Fields(5).Value
itm.SubItems(5) = .Fields(6).Value
End With
Set itm = Nothing
End Sub
vb 关键字 不唯一 --------------------编程问答-------------------- 相同的记录位置如果执行两次,就会出现该问题
增加一个判断函数
function TestKey(sKey as string)as listitem
on error resume next
set TestKey=lvw.listitems(skey)
end function
'''''''''''''''''''''''''''
将Set itm = lvw.ListItems.Add(, "A" & objClient("clkID"), , bIcon, sIcon)
改为:
dim sKey as string
skey="A" & objClient("clkID")
if testkey(skey) is nothing then
Set itm = lvw.ListItems.Add(, "A" & objClient("clkID"), , bIcon, sIcon)
end if
--------------------编程问答-------------------- 只能算是参考信息,Collection类可以扩充一个Contains方法
补充:VB , 基础类