Listview项目在vb.net中显示重复项 [英] Listview item displays duplicate in vb.net
问题描述
我正在处理此代码,我注意到我会得到列表,它从0开始,然后为计算机上安装的每个应用程序创建一行.我遇到的问题是,当我查询列表项目1时,它会显示在列表的开头和最后一个项目中.请帮助我尝试更改代码,但是我不知道我在哪里乱窜,我无法重复任何项目.
在列表中将显示
例子.
0.adobe阅读器
1.office 2010
2. IE8
3.Office 2010
现在我通常在列表中有50个项目,而#1将是那个,编号为#51.
I m working on this code and i have noticed that i will get the list and it starts from 0 then creates a line for every application thats installed on the computer. The issue i m having is when i query the list item #1 shows at the beggining and the last item in the list. Please help i have tried changing the code but i dont know where i m goofing up at i cant have any item repeating itself.
in the list it will show
Example.
0.adobe reader
1.office 2010
2. IE8
3.Office 2010
now i normally have 50 items in the list and #1 will be that and number #51.
objsh = CreateObject("WScript.Shell")
strObject = "C:\Temp\ASERVICE.EDM"
Dim process = GetObject("winmgmts://./root/novadigm:NVD_Agent")
Dim method = process.Methods_("GetValue")
Dim inParameters = method.inParameters.SpawnInstance_()
inParameters.Path = strObject
Dim outParameters = process.ExecMethod_("NumberOfInstances", inParameters)
Dim StrHeaps = (outParameters.InstanceCount)
num_TextBox.Text = StrHeaps
For i = 0 To StrHeaps Step +1
inParameters.Index = i
inParameters.Property = "ZOBJNAME"
outParameters = process.ExecMethod_("GetValue", inParameters)
Dim Value1 As String = outParameters.Value
inParameters.Property = "ZAVIS"
outParameters = process.ExecMethod_("GetValue", inParameters)
Dim Value2 As String = outParameters.Value
inParameters.Property = "NAME"
outParameters = process.ExecMethod_("GetValue", inParameters)
Dim Value3 As String = outParameters.Value
inParameters.Property = "INSTDATE"
outParameters = process.ExecMethod_("GetValue", inParameters)
Dim value5 As String = outParameters.Value
'Date
Dim str As String
Dim strArr() As String
Dim count As Integer
Dim value6 As String
str = value5
strArr = str.Split("T")
For count = 0 To strArr.Length - 2
value6 = (strArr(count))
Next
Dim value4 = ListView1.Items.Count
Dim item As New ListViewItem(value4)
item.SubItems.Add(Value1)
item.SubItems.Add(Value2)
item.SubItems.Add(Value3)
item.SubItems.Add(value6)
ListView1.Items.Add(item)
ListView1.FullRowSelect = True
Next
End Sub
推荐答案
如果您设置了一个断点,则可以单步执行代码并亲自查看该值在哪里弄乱了.
考虑给变量赋予有意义的名称,而不是ListBox1,Value1和Value2.
If you set a breakpoint, you can step through your code and see for yourself where the value is getting messed up.
Consider giving your variables meaningful names instead of ListBox1, Value1 and Value2.
我想出了如何通过代码删除重复项:
Cae1.ListView1.Items(Cae1.ListView1.Items.Count-1).Remove()
希望这对其他人有帮助.
i figured out how to remove the duplicate via code:
Cae1.ListView1.Items(Cae1.ListView1.Items.Count - 1).Remove()
hope this helps someone else.
这篇关于Listview项目在vb.net中显示重复项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!