我有一个这样的自定义对象:
Dim Contacts As New List(Of Contact)
Dim CurrentContact As Contact = New Contact With { _
.Name = "Manolo", _
.Country = "Spain", _
.City = "Valencia"}
Contacts.Add(CurrentContact)
成员变量只是字符串:
<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
现在我有一个设置了“详细信息”模式和 3 列的Listview ,如下所示:
Name Column | Country Column | City Column
------------------------------------------------------------------
(Here goes Item) | (Here goes Subitem 1) | (Here goes Subitem 2)
我的问题,如何使用 LINQ 直接转换所需列中的每个值?所以结果是这样的:
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...
我尝试将对象转换为“ ListViewItem ”、“ ListviewGroup ”和“ ListView.ListViewItemCollection ”,但没有任何效果,我做错了,异常显示“ 'contact' 类型的值不能转换为 String ”:
ListView1.Items.AddRange(Contacts.Select(Function(x) New ListViewGroup(x)).ToArray)
这会引发“ 'contact' 类型的值不能转换为 ListViewGroup ”
ListView1.Items.AddRange(Contacts.Select(Function(x) New ListViewItem(x)).ToArray)