Reputation: 703
The short version:
How can I add information to a specific column and row in a listview?
The longer version:
With some textboxes and buttons in another form I add items to my listview like this
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()
This is the output so far...
Tbname1.text
(Column below Channel) and tbtype1.text
(Column below Type) are specified in textboxes before i hit the button.
Tbcount1.text
in form1 contains a number based on count of files within a folder. TbStatus.text
is based on how many files there are. This count is hooked to another button (eventually a timer). This is why you'll notice Queue and Status is empty.
Now if I'd hit that button (or timer) - lets say btnUpdate
before the settings in my other form, it would look like this
Here comes the problem...
I now want to update only the information under the column Queue (tbcount1.text) and Status (tbstatus.text) with btnUpdate
For example I have this counter
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
Which works perfectly. It gives me the number and word I want in the two textboxes, but at the moment I have to refresh the whole listview to get that count-output into the columns.
I've tried...
To add this under the 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)
Sadly, this jumps to a second row. See image below.
So here is what I want in other words: when btnupdate
is pressed or a timer is at 100; update specified row - column 3 with tbcount.text
and update specified row - column 5 with tbstatus.text
. That wraps up my question.
I found some information on this in C#, but I need it in VB.net. I might be close or far away. Hopefully it was understandable anyways.
Upvotes: 0
Views: 5636
Reputation: 3710
You can easily manipulate the listview items directly whenever you want.
If you have the item selected, that you want to change, you simply access it like this:
myListview.selecteditems(0).text = ""
myListview.selecteditems(0).subitems(1).text
myListview.selecteditems(0).subitems(2).text
myListview.selecteditems(0).subitems(3).text
You dont have to re-assign the whole listviewitem every time you change it, just change whatever needs changing...
If you do not have the item selected in the listview (row), you will have to step through the listviewitems collection until you find the item (row) you are looking for, and then manipulate whatever parts of it you need to.
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
Note: Subitems are (1) based, not 0...
Upvotes: 3