2

它曾经完美地工作......但现在它正在触发一个错误,我不知道为什么。这是我的代码:

    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
4

1 回答 1

1

这假设列表视图中已经有一个选定的项目,但可能没有;

if not ListView1.SelectedItem is nothing then
 ListView1.SelectedItem.Selected = False
end if
于 2013-11-13T11:45:43.830 回答