I am trying to add a List(Of T) to a Listview in Windows form application.But not able to do it.
I have made a form and took the value of textboxes in a list and trying to bind the list to ListView

Recommended Answers

You can try writing a custom fill function:

Private Function Fill(ByVal lstIN As List(Of T)) As Boolean
    Try
        Dim lvi As New ListViewItem

        lvi.Text = lstIN(0) 'if index 0 is a unique - Column 1
        lvi.SubItems.Add(lstIN(1)) 'Column 2 in listview
        lvi.SubItems.Add(lstIN(2)) 'Column 3

        ListView1.Items.Add(lvi)

        Return True
    Catch …
Jump to Post

All 2 Replies

You can try writing a custom fill function:

Private Function Fill(ByVal lstIN As List(Of T)) As Boolean
    Try
        Dim lvi As New ListViewItem

        lvi.Text = lstIN(0) 'if index 0 is a unique - Column 1
        lvi.SubItems.Add(lstIN(1)) 'Column 2 in listview
        lvi.SubItems.Add(lstIN(2)) 'Column 3

        ListView1.Items.Add(lvi)

        Return True
    Catch ex As Exception
        Return False
    End Try
End Function

If your list is a simple or integrated type and you only need 1 column, you can use it as a datasource for a Listbox, which is basically the same output.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.