简短版本:
如何将信息添加到列表视图中的特定列和行?
版本较长:
对于某些文本框和其他形式的按钮,我将项目添加到我的列表视图中,如此
Dim li As ListViewItem
li = Form1.ListView1.Items.Add("1")
li.SubItems.Add(tbName1.Text)
li.SubItems.Add(Form1.tbCount1.Text)
li.SubItems.Add(tbType1.Text)
li.SubItems.Add(Form1.tbStatus1.Text)
Form1.ListView1.EndUpdate()
Form1.ListView1.Refresh()
这是迄今为止的输出......
在我按下按钮之前, Tbname1.text
(频道下方的列)和tbtype1.text
(类型下方的列)在文本框中指定。
Tbcount1.text
包含基于文件夹中文件计数的数字。 TbStatus.text
基于有多少文件。此计数挂钩到另一个按钮(最终是一个计时器)。这就是您注意到队列和状态为空的原因。
现在,如果我点击该按钮(或计时器) - 在我的其他表单设置之前说出btnUpdate
,它就会显示为
问题出现了......
我现在想要使用btnUpdate
例如我有这个计数器
If Form2.cbc1.Checked = True Then
Try
Dim fileTotal As Integer
For Each item As String In lbChannel1.Items
fileTotal += My.Computer.FileSystem.GetFiles(item.ToString).Count
Next
tbCount1.Text = String.Format("{0}", fileTotal.ToString)
Catch ex As Exception
lbErrors.Items.Add(String.Concat("Error: ", ex.Message)) 'Error output
End Try
Dim tCount As Integer = 0
'Til status
If Val(tbCount1.Text) > 20 Then
tbStatus1.Text = ("Many files")
Else
tbStatus1.Text = ("Good")
End If
End If
完美无缺。它给了我两个文本框中我想要的数字和单词,但是此刻我必须刷新整个listview才能将count-output输入到列中。
我已经尝试过了......
在btnUpdate
...
Dim str(4) As String
Dim itm As ListViewItem
str(0) = ""
str(1) = ""
str(2) = (tbCount1.Text)
str(3) = ""
str(4) = (tbStatus1.Text)
itm = New ListViewItem(str)
ListView1.Items.Add(itm)
可悲的是,这跳到了第二排。见下图。
所以这就是我想要的东西:当按下btnupdate
或计时器是100时;使用tbcount.text
更新指定行 - 第3列并使用tbstatus.text
更新指定行 - 第5列。这结束了我的问题。
我在C#中找到了一些相关信息,但我需要在VB.net中使用它。我可能很近或远。希望无论如何它是可以理解的。
答案 0 :(得分:2)
您可以随时轻松地直接操作列表视图项目。
如果您选择了要更改的项目,则只需按以下方式进行更改:
myListview.selecteditems(0).text = ""
myListview.selecteditems(0).subitems(1).text
myListview.selecteditems(0).subitems(2).text
myListview.selecteditems(0).subitems(3).text
每次更改时都不必重新分配整个listviewitem,只需更改需要更改的内容......
如果您没有在列表视图(行)中选择该项目,则必须单步执行listviewitems集合,直到找到要查找的项目(行),然后操纵所需的任何部分。
For each item in mylistview.items
if item.text = "whatoever"
'this is my item....
'manipulate it....
item.text = "sdfdsf"
item.subitems(1).text = "ddsfdsfdsa"
'etc
end if
next
注意:子项是基于(1)的,而不是0 ...