我正在用vb / windows表单编写一个工具,它将删除远程计算机上的用户配置文件。除了显示已删除的计算机名称和配置文件外,它的效果很好。
当我尝试ObjectListView时,它会显示第一行的信息,并为每台计算机覆盖它,并在每台计算机上删除每个配置文件。以下是我遇到问题的代码的一部分......
Public Class PC
Public Property Computer_Name As String
Public Property Profile_Name As String
End Class
-
For Each objProfile In colProfiles
Dim dtmLastUseTime = CDate(Mid(objProfile.LastUseTime, 5, 2) & "/" &
Mid(objProfile.LastUseTime, 7, 2) & "/" & VB.Left(objProfile.LastUseTime, 4) _
& " " & Mid(objProfile.LastUseTime, 9, 2) & ":" &
Mid(objProfile.LastUseTime, 11, 2) & ":" & Mid(objProfile.LastUseTime,
13, 2))
If DateDiff("d", dtmLastUseTime, d1) > intMaxProfileAge Then
usrPath = objProfile.localpath
rowInfo2 = usrPath
Dim LvItm As New PC With {.Computer_Name = rowInfo1, .Profile_Name = rowInfo2}
Dim LvLst As New List(Of PC)
LvLst.Add(LvItm)
ObjectListView1.SetObjects(LvLst)
objProfile.Delete_
End If
Next
答案 0 :(得分:0)
尝试替换此:
Dim LvLst As New List(Of PC)
LvLst.Add(LvItm)
ObjectListView1.SetObjects(LvLst)
在:
ObjectListView1.AddObject(LvLst)
或强>
移动此行
Dim LvLst As New List(Of PC)
在strat for-each循环之前,这一行
ObjectListView1.SetObjects(LvLst)
在next
行之后。