Reading VB.net from a multi-column list

Good. So I was able to learn how to read from the first column, but I need to read them both. I use the full row selection that I need.

Here is the code that I use 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
+3
source share
2 answers

The answer to the correct answer is just an option:

For Each item As ListViewItem In ListView1.SelectedItems
    Debug.WriteLine("Col1 {0}, Col2 {1}", item.Text, item.SubItems(1).Text)
Next
+2
source

The text of the column (s) is in the SubItem array of the list item.

so you do something like ... (VB is not my first language, so it is not verified)

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, it is usually not recommended to pop up a message box in a loop)

+3
source

Source: https://habr.com/ru/post/1745718/


All Articles