My software is designed to encrypt and decrypt files. The user loads the files to be processed into a ListView control. In the control, each item is the file path with one subitem, the type of process (ENCRYPT or DECRYPT).
I need to get a list of all ITEMS (the file paths) that have the “ENCRYPT” subitem, preferably with LINQ. Currently, my code looks like this:
Dim enclist As New ArrayList()
For i As Int32 = 0 To (lvwLoad.Items.Count - 1)
If lvwLoad.Items(i).SubItems(1).Text = "ENCRYPT" Then
enclist.Add(lvwLoad.Items.Item(i).Text)
count += 1
End If
Next
I tried this:
Dim list As IEnumerable(Of String) = From item In lvwLoad.Items
Where item.SubItems(1).Text = "ENCRYPT"
But this statement can’t access the SubItems() array. I know there’s probably something simple I’m missing, but I can’t figure it out.
EDIT:
I know I can do this:
Dim enclist As New List(Of String)
For Each item As ListViewItem In lvwLoad.Items
If item.SubItems(1).Text = "ENCRYPT" Then
enclist.Add(item.Text)
End If
Next
But I really want to know how to do this with LINQ.
Try code below, you need to cast items to
ListViewItemso that you can accessSubItems