I have written some code to load a list of type Author to a ListView. Here is my code:
May I have some help to use a list of any type for this code? I have changed the following code:
But now my Author list will not work with this code. How can I cast a List of Author (or any object) to a List of Object?
Code:
Public Sub LoadListToListView(ListView As ListView, ListToLoad As List(Of Author), ListOfPropertiesToAdd As List(Of String))
Dim Info() As PropertyInfo
Dim ListViewItemToAdd As New ListViewItem
ListView.Items.Clear()
ListView.BeginUpdate()
For x = 0 To ListToLoad.Count - 1
ListViewItemToAdd = New ListViewItem
Info = ListToLoad(x).GetType().GetProperties()
For y = 0 To ListOfPropertiesToAdd.Count - 1
If y = 0 Then
ListViewItemToAdd.Text = GetPropertyValue(ListToLoad(x), ListOfPropertiesToAdd(y)).ToString
Else
ListViewItemToAdd.SubItems.Add(GetPropertyValue(ListToLoad(x), ListOfPropertiesToAdd(y)).ToString)
End If
Next
ListView.Items.Add(ListViewItemToAdd)
Next
ListView.EndUpdate()
End Sub
Code:
ListToLoad As List(Of Object)