VB.net Reading from ListViews with Multiple Columns
Alright. So I was able to find out how to read from the first column but I need to read from both of them. I am us开发者_StackOverflow中文版ing full row select which I need on there.
Here is the code I am using to get it for the first column.
Dim I As Integer
For I = 0 To ListView1.SelectedItems.Count - 1
MsgBox(ListView1.SelectedItems(I).Text)
Next
The Column(s) text is located in the SubItem array of the list view item.
so you would do something like...(VB is not my 1st language so this is untested)
dim i as Integer
dim item as ListViewItem
for i = 0 to ListView1.SelectedItems.Count -1
item = ListView1.SelectedItems(i)
Console.WriteLine(Col1 = {0} Col2 = {1},item.SubItems(0),item.SubItems(1))
next
(note, usually not a good idea to pop up a messagebox in a loop)
Tim's answer is correct this is just a variant of it:
For Each item As ListViewItem In ListView1.SelectedItems
Debug.WriteLine("Col1 {0}, Col2 {1}", item.Text, item.SubItems(1).Text)
Next
精彩评论