Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27333

VS 2012 [RESOLVED] Cast a List Of Type to List of Object

$
0
0
I have written some code to load a list of type Author to a ListView. Here is my code:

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

May I have some help to use a list of any type for this code? I have changed the following code:

Code:

ListToLoad As List(Of Object)
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?

Viewing all articles
Browse latest Browse all 27333

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>