I have a custom object like this:
Dim Contacts As New List(Of Contact)
Dim CurrentContact As Contact = New Contact With { _
.Name = "Manolo", _
.Country = "Spain", _
.City = "Valencia"}
Contacts.Add(CurrentContact)
The member vars are just Strings:
<Serializable()> _
Public Class Contact
#Region "Member Variables"
Private mId As System.Guid
Private mName As String
Private mCountry As String
Private mCity As String
#End Region
End Class
Now I have a Listview with "Details" mode set and with 3 columns like this:
Name Column | Country Column | City Column
------------------------------------------------------------------
(Here goes Item) | (Here goes Subitem 1) | (Here goes Subitem 2)
My question, How I can use LINQ to directly cast each value in the desired column? so the result would be this:
Name Column | Country Column | City Column
--------------------------------------------------------
Manolo | Spain | Valencia
Next contact Name | Next contact Country | Next contact City
Next contact Name | Next contact Country | Next contact City
etc...
I've tried to cast the object as "ListViewItem", "ListviewGroup" and "ListView.ListViewItemCollection" but nothing worked, I'm doing something wrong, the exception says "Value of type 'contact' cannot be converted to String":
ListView1.Items.AddRange(Contacts.Select(Function(x) New ListViewGroup(x)).ToArray)
And this else throws a "Value of type 'contact' cannot be converted to ListViewGroup"
ListView1.Items.AddRange(Contacts.Select(Function(x) New ListViewItem(x)).ToArray)