它过去工作得很完美......但是现在它发出错误,我不明白为什么。这是我的代码:
Private Function bListNames() As Boolean
On Error GoTo Treat_Errors
Dim lLinha As Long
bListaNomes = False
ListView1.ColumnHeaders.Clear
ListView1.ListItems.Clear
Set clmX = ListView1.ColumnHeaders.Add(1, , "Desc", 4000)
Set clmX = ListView1.ColumnHeaders.Add(2, , "Cod", 1000, 1)
lLinha = 1
Do While Not rstListNames.EOF
Set itmX = ListView1.ListItems.Add(lLinha, , "" & rstListNames.Fields(1))
itmX.SubItems(1) = format(rstListNames.Fields(0), "000000")
rstListNames.MoveNext
lLinha = lLinha + 1
Loop
ListView1.SelectedItem.Selected = False
bListaNomes = True
bRetorno = True
Exit Function
Trata_Erros:
Exibe_Erros Err.Description, Err.Number
End Function
它开火了:
<Object Variable or With Block variable not Set>
在这一行:
ListView1.SelectedItem.Selected = False
答案 0 :(得分:1)
假设列表视图中已经有一个选定的项目可能没有;
if not ListView1.SelectedItem is nothing then
ListView1.SelectedItem.Selected = False
end if